package com.xinyirun.scm.core.system.mapper.business.monitor;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinyirun.scm.bean.api.vo.business.monitor.ApiMonitorVo;
import com.xinyirun.scm.bean.entity.business.monitor.BMonitorEntity;
import com.xinyirun.scm.bean.system.vo.business.monitor.*;
import com.xinyirun.scm.bean.system.vo.business.wms.inventory.*;
import com.xinyirun.scm.common.constant.DictConstant;
import com.xinyirun.scm.common.constant.SystemConstants;
import com.xinyirun.scm.core.system.config.mybatis.typehandlers.BMonitorFileVoTypeHandler;
import com.xinyirun.scm.core.system.config.mybatis.typehandlers.BMonitorPreviewFileVoTypeHandler;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author htt
 * @since 2021-09-23
 */
@Repository
public interface BMonitorMapper extends BaseMapper<BMonitorEntity> {

    String common_select = "  "
            + "     SELECT                                                                                                                                      "
            + "            t30.code container_code,                                                                                                             "
            + "            t.*,                                                                                                                                 "
            + "            t13.label status_name,                                                                                                               "
            + "            t24.label audit_status_name,                                                                                                         "
            + "            t25.label settlement_status_name,                                                                                                    "
            + "            t4.code as schedule_code,                                                                                                            "
            + "            t4.type as schedule_type,                                                                                                            "
            + "            ifnull(t20.type,t21.type) as in_type,                                                                                                "
            + "            ifnull(t22.type,t23.type) as out_type,                                                                                               "
            + "            ifnull(t20.qty,t21.qty) as in_qty,                                                                                                   "
            + "            ifnull(t22.qty,t23.qty) as out_qty,                                                                                                  "
            + "            case when ifnull(t20.type,t21.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0                                        "
            + "            else ifnull(ifnull(t22.qty,t23.qty) - ifnull(t20.qty,t21.qty), 0) - ifnull(t35.qty,0)  end as qty_loss,                                                   "
            + "            case when ifnull(t20.type,t21.type) = '"+ SystemConstants.MONITOR.B_MONITOR_IN +"' then '入库' when                                   "
            + "             ifnull(t20.type,t21.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then '卸货' else '' end as in_type_name,                "
            + "            case when ifnull(t22.type,t23.type) = '"+ SystemConstants.MONITOR.B_MONITOR_OUT +"' then '出库' when                                  "
            + "             ifnull(t22.type,t23.type) = '"+ SystemConstants.MONITOR.B_MONITOR_DELIVERY +"' then '提货' else '' end as out_type_name,             "
            + "            ifnull(t20.id,t21.id) as monitor_in_id,                                                                                              "
            + "            t.in_time as monitor_finish_time,                                                                                                    "
            + "            ifnull(t22.id,t23.id) as monitor_out_id,                                                                                             "
            + "            t4.out_plan_code,                                                                                                                    "
            + "            t4.in_plan_code,                                                                                                                     "
            + "            ifnull(t6.short_name, t6.name) out_warehouse_name,                                                                                   "
            + "            t4.out_warehouse_address,                                                                                                            "
            + "            ifnull(t5.short_name, t5.name) in_warehouse_name,                                                                                    "
            + "            t4.in_warehouse_address,                                                                                                             "
            + "            ifnull(t10.contract_no,t4.contract_no) contract_no,                                                                                  "
            + "            t11.name as goods_name,                                                                                                              "
            + "            t11.spec as sku_name,                                                                                                                "
            + "            t11.pm as pm,                                                                                                                        "
            + "            t11.code as sku_code,                                                                                                                "
            + "            t7.name as customer_name,                                                                                                            "
            + "            t8.no as vehicle_no,                                                                                                                 "
            + "            t8.gps_time as validate_gps_time,                                                                                                    "
            + "            t8.validate_log as validate_log,                                                                                                     "
            + "            t9.name as driver_name,                                                                                                              "
            + "            t9.mobile_phone as driver_mobile_phone,                                                                                              "
            + "            t1.name as c_name,                                                                                                                   "
            + "            t14.code as out_code,                                                                                                                "
            + "            t15.code as in_code,                                                                                                                 "
            + "            t16.label as out_status_name,                                                                                                        "
            + "            t17.label as in_status_name,                                                                                                         "
            + "            t14.status as out_status,                                                                                                            "
            + "            t15.status as in_status,                                                                                                             "
            + "            t2.name as u_name,                                                                                                                   "
            + "            t26.name as in_audit_name,                                                                                                           "
            + "            t27.name as out_audit_name,                                                                                                          "
            + "            t28.waybill_contract_no,                                                                                                             "
            + "            t3.label in_warehouse_type_name,                                                                                                     "
            + "            t12.label out_warehouse_type_name,                                                                                                   "
            + "            t19.status backup_status,                                                                                                            "
            + "            case t19.type when '1' then t29.label when '2' then '备份恢复' else '' end  backup_status_name,                                       "
            + "            t19.flag backup_flag,                                                                                                                "
            + "            t19.type backup_type,                                                                                                                "
            + "            t32.label vehicle_color,                                                                                                             "
            + "            ifnull(t10.id,t4.order_id) order_id,                                                                                                 "
            + "            t18.remark as cancel_remark,                                                                                                         "
            + "            ifnull(t35.qty,0) as return_qty,                                                                                                "
            + "            IF(ifnull(t35.qty,0)> 0,'是','否') as if_return_qty_name,                                                                        "
            + "            case t4.type when '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"' then t.in_audit_time                                                     "
            + "            when '"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"' then t.out_audit_time else null end audit_time,                                       "
            + "            case t4.type when '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"' then t26.name                                                            "
            + "            when '"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"' then t27.name else null end audit_name                                                "
            + "       FROM                                                                                                                                      "
            + "  	        b_monitor t                                                                                                                         "
            + "  LEFT JOIN m_staff t1 ON t.c_id = t1.id                                                                                                         "
            + "  LEFT JOIN m_staff t2 ON t.u_id = t2.id                                                                                                         "
            + "  LEFT JOIN b_schedule t4 ON t4.id = t.schedule_id                                                                                               "
            + "  LEFT JOIN m_warehouse t5 ON t4.in_warehouse_id = t5.id                                                                                         "
            + "  LEFT JOIN m_warehouse t6 ON t4.out_warehouse_id = t6.id                                                                                        "
            + "  LEFT JOIN m_customer t7 ON t.customer_id = t7.id                                                                                               "
            + "  LEFT JOIN m_vehicle t8 ON t.vehicle_id = t8.id                                                                                                 "
            + "  LEFT JOIN m_driver t9 ON t.driver_id = t9.id                                                                                                   "
            + "  LEFT JOIN b_order t10 on t10.serial_type in ('b_in_order','b_out_order') and t4.order_id = t10.id                                             "
            + "  LEFT JOIN m_goods_spec t11 ON t4.sku_id = t11.id                                                                                               "
            + "  LEFT JOIN v_dict_info t13 ON t13.code = 'b_monitor_status' and t.status = t13.dict_value                                                       "
            + "  LEFT JOIN b_monitor_in t20 ON t20.monitor_id = t.id                                                                                            "
            + "  LEFT JOIN b_monitor_unload t21 ON t21.monitor_id = t.id                                                                                        "
            + "  LEFT JOIN b_monitor_out t22 ON t22.monitor_id = t.id                                                                                           "
            + "  LEFT JOIN b_monitor_delivery t23 ON t23.monitor_id = t.id                                                                                      "
            + "  LEFT JOIN b_out t14 on t22.out_id = t14.id                                                                                                     "
            + "  LEFT JOIN b_in t15 on t20.in_id = t15.id                                                                                                       "
            + "  LEFT JOIN v_dict_info t16 ON t16.code = '"+DictConstant.DICT_B_OUT_STATUS+"' and t14.status = t16.dict_value                                   "
            + "  LEFT JOIN v_dict_info t17 ON t17.code = '"+DictConstant.DICT_B_IN_STATUS+"' and t15.status = t17.dict_value                                    "
            + "  LEFT JOIN m_cancel t18 ON t18.serial_id = t.id and t18.serial_type = '"+SystemConstants.SERIAL_TYPE.B_MONITOR+"'                               "
            + "  LEFT JOIN v_dict_info t24 ON t24.code = '"+DictConstant.DICT_B_MONITOR_AUDIT_STATUS+"' and t.audit_status = t24.dict_value                     "
            + "  LEFT JOIN v_dict_info t25 ON t25.code = '"+DictConstant.DICT_B_MONITOR_SETTLEMENT_STATUS+"' and t.settlement_status = t25.dict_value           "
            + "  LEFT JOIN m_staff t26 ON t.in_audit_id = t26.id                                                                                                "
            + "  LEFT JOIN m_staff t27 ON t.out_audit_id = t27.id                                                                                               "
            + "  LEFT JOIN b_schedule_info t28 ON t4.id = t28.schedule_id                                                                                       "
            + "  LEFT JOIN v_dict_info t3 ON t3.code = '"+DictConstant.DICT_M_WAREHOUSE_TYPE+"' and t5.warehouse_type = t3.dict_value                           "
            + "  LEFT JOIN v_dict_info t12 ON t12.code = '"+DictConstant.DICT_M_WAREHOUSE_TYPE+"' and t6.warehouse_type = t12.dict_value                        "
            + "  LEFT JOIN b_bk_monitor_sync_log t19 ON t19.monitor_id = t.id                                                                                   "
            + "  LEFT JOIN v_dict_info t29 ON t29.code = '"+DictConstant.DICT_B_MONITOR_BACKUP_DETAIL_STATUS+"' and t19.status = t29.dict_value                 "
            + "  LEFT JOIN m_container t30 ON t30.id = t.container_id                                                                                           "
            + "  LEFT JOIN v_dict_info t32 ON t32.code = '"+DictConstant.DICT_M_VEHICLE_COLOR+"' and t8.no_color = t32.dict_value                               "
            + "  LEFT JOIN b_schedule t34 ON t34.id = t.schedule_id                                                                                             "
            + "  LEFT JOIN b_return_relation t35 ON t35.serial_id = t.id AND t35.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
            + "  AND  t35.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
            ;

    String common_select_export = "  "
            + "     SELECT                                                                                                                                                  "
            + "            @row_num:= @row_num+ 1 as no,                                                                                                                    "
            + "            t.code,                                                                                                                                          "
            + "            t13.label status_name,                                                                                                                           "
            + "            t24.label audit_status_name,                                                                                                                     "
            + "            t25.label settlement_status_name,                                                                                                                "
            + "            t4.code as schedule_code,                                                                                                                        "
            + "            ifnull(t10.contract_no,t4.contract_no) contract_no,                                                                                              "
            + "            t28.waybill_contract_no,                                                                                                                         "
            + "            t4.in_plan_code,                                                                                                                                 "
            + "            t4.out_plan_code,                                                                                                                                "
            + "            t.waybill_code,                                                                                                                                  "
            + "            case when ifnull(t22.type,t23.type) = '"+ SystemConstants.MONITOR.B_MONITOR_OUT +"' then '出库' when                                              "
            + "             ifnull(t22.type,t23.type) = '"+ SystemConstants.MONITOR.B_MONITOR_DELIVERY +"' then '提货' else '' end as out_type_name,                         "
            + "            ifnull(t6.short_name, t6.name) out_warehouse_name,                                                                                               "
            + "            t4.out_warehouse_address,                                                                                                                        "
            + "            DATE_FORMAT(t.out_time,'%Y年%m月%d日 %H:%i:%s') out_time,                                                                                         "
            + "            case when ifnull(t20.type,t21.type) = '"+ SystemConstants.MONITOR.B_MONITOR_IN +"' then '入库' when                                               "
            + "             ifnull(t20.type,t21.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then '卸货' else '' end as in_type_name,                            "
            + "            ifnull(t5.short_name, t5.name) in_warehouse_name,                                                                                                "
            + "            t4.in_warehouse_address,                                                                                                                         "
            + "            DATE_FORMAT(t.in_time,'%Y年%m月%d日 %H:%i:%s') in_time,                                                                                           "
            + "            t11.name as goods_name,                                                                                                                          "
            + "            t11.pm as pm,                                                                                                                                    "
            + "            t11.spec,                                                                                                                                        "
            + "            t11.code as sku_code,                                                                                                                            "
            + "            t7.name as customer_name,                                                                                                                        "
            + "            concat(ifnull(t9.name, ''), if(t9.mobile_phone is null, '', concat(' ( ', t9.mobile_phone, ' )'))) as driver_name,                               "
            + "            t8.no as vehicle_no,                                                                                                                             "
            + "            if(t.validate_vehicle, '验车通过', '验车未通过') validate_vehicle,                                                                                  "
            + "            ifnull(t22.qty,t23.qty) as out_qty,                                                                                                              "
            + "            ifnull(t20.qty,t21.qty) as in_qty,                                                                                                               "
            + "            case when ifnull(t20.type,t21.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0 else                                               "
            + "            if(ifnull(t22.qty,t23.qty) &lt;= ifnull(t20.qty,t21.qty), 0, ifnull(ifnull(t22.qty,t23.qty) - ifnull(t20.qty,t21.qty) - ifnull(t35.qty,0), 0)) end as qty_loss,      "
            + "            t18.remark as cancel_remark,                                                                                                                     "
            + "            t27.name as out_audit_name,                                                                                                                      "
            + "            DATE_FORMAT(t.out_audit_time,'%Y年%m月%d日 %H:%i:%s') out_audit_time,                                                                             "
            + "            DATE_FORMAT(t.in_audit_time,'%Y年%m月%d日 %H:%i:%s') in_audit_time,                                                                               "
            + "            t26.name as in_audit_name,                                                                                                                       "
            + "            t1.name as c_name,                                                                                                                               "
            + "            DATE_FORMAT(t.c_time,'%Y年%m月%d日 %H:%i:%s') c_time,                                                                                             "
            + "            t2.name as u_name,                                                                                                                               "
            + "            t3.label in_warehouse_type_name,                                                                                                                 "
            + "            t12.label out_warehouse_type_name,                                                                                                               "
            + "            t30.code container_code,                                                                                                                         "
            + "            DATE_FORMAT(t.u_time,'%Y年%m月%d日 %H:%i:%s') u_time,                                                                                             "
            + "            case t19.type when '1' then t29.label when '2' then '备份恢复' else '' end  backup_status_name,                                                   "
            + "            t19.flag backup_flag,                                                                                                                            "
            + "            ifnull(t35.qty,0) as return_qty,                                                                                                            "
            + "            IF(ifnull(t35.qty,0)> 0,'是','否') as if_return_qty_name,                                                                                    "
            + "            case t4.type when '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"' then t.in_audit_time                                                                 "
            + "            when '"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"' then t.out_audit_time else null end audit_time,                                                   "
            + "            case t4.type when '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"' then t26.name                                                                        "
            + "            when '"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"' then t27.name else null end audit_name                                                            "
            + "       FROM                                                                                                                                                  "
            + "  	        b_monitor t                                                                                                                                     "
            + "  LEFT JOIN m_staff t1 ON t.c_id = t1.id                                                                                                                     "
            + "  LEFT JOIN m_staff t2 ON t.u_id = t2.id                                                                                                                     "
            + "  LEFT JOIN b_schedule t4 ON t4.id = t.schedule_id                                                                                                           "
            + "  LEFT JOIN m_warehouse t5 ON t4.in_warehouse_id = t5.id                                                                                                     "
            + "  LEFT JOIN m_warehouse t6 ON t4.out_warehouse_id = t6.id                                                                                                    "
            + "  LEFT JOIN m_customer t7 ON t.customer_id = t7.id                                                                                                           "
            + "  LEFT JOIN m_vehicle t8 ON t.vehicle_id = t8.id                                                                                                             "
            + "  LEFT JOIN m_driver t9 ON t.driver_id = t9.id                                                                                                               "
            + "  LEFT JOIN b_order t10 on t10.serial_type in ('b_in_order','b_out_order') and t4.order_id = t10.id                                                          "
            + "  LEFT JOIN m_goods_spec t11 ON t4.sku_id = t11.id                                                                                                           "
            + "  LEFT JOIN v_dict_info t13 ON t13.code = 'b_monitor_status' and t.status = t13.dict_value                                                                   "
            + "  LEFT JOIN b_monitor_in t20 ON t20.monitor_id = t.id                                                                                                        "
            + "  LEFT JOIN b_monitor_unload t21 ON t21.monitor_id = t.id                                                                                                    "
            + "  LEFT JOIN b_monitor_out t22 ON t22.monitor_id = t.id                                                                                                       "
            + "  LEFT JOIN b_monitor_delivery t23 ON t23.monitor_id = t.id                                                                                                  "
            + "  LEFT JOIN b_out t14 on t22.out_id = t14.id                                                                                                                 "
            + "  LEFT JOIN b_in t15 on t20.in_id = t15.id                                                                                                                   "
            + "  LEFT JOIN v_dict_info t16 ON t16.code = '"+DictConstant.DICT_B_OUT_STATUS+"' and t14.status = t16.dict_value                                               "
            + "  LEFT JOIN v_dict_info t17 ON t17.code = '"+DictConstant.DICT_B_IN_STATUS+"' and t15.status = t17.dict_value                                                "
            + "  LEFT JOIN m_cancel t18 ON t18.serial_id = t.id and t18.serial_type = '"+SystemConstants.SERIAL_TYPE.B_MONITOR+"'                                           "
            + "  LEFT JOIN v_dict_info t24 ON t24.code = '"+DictConstant.DICT_B_MONITOR_AUDIT_STATUS+"' and t.audit_status = t24.dict_value                                 "
            + "  LEFT JOIN v_dict_info t25 ON t25.code = '"+DictConstant.DICT_B_MONITOR_SETTLEMENT_STATUS+"' and t.settlement_status = t25.dict_value                       "
            + "  LEFT JOIN m_staff t26 ON t.in_audit_id = t26.id                                                                                                            "
            + "  LEFT JOIN m_staff t27 ON t.out_audit_id = t27.id                                                                                                           "
            + "  LEFT JOIN b_schedule_info t28 ON t4.id = t28.schedule_id                                                                                                   "
            + "  LEFT JOIN v_dict_info t3 ON t3.code = '"+DictConstant.DICT_M_WAREHOUSE_TYPE+"' and t5.warehouse_type = t3.dict_value                                       "
            + "  LEFT JOIN v_dict_info t12 ON t12.code = '"+DictConstant.DICT_M_WAREHOUSE_TYPE+"' and t6.warehouse_type = t12.dict_value                                    "
            + "  LEFT JOIN m_container t30 ON t30.id = t.container_id                                                                                           "
            + "  LEFT JOIN b_bk_monitor_sync_log t19 ON t19.monitor_id = t.id                                                                                   "
            + "  LEFT JOIN v_dict_info t29 ON t29.code = '"+DictConstant.DICT_B_MONITOR_BACKUP_DETAIL_STATUS+"' and t19.status = t29.dict_value                 "
            + "  LEFT JOIN b_schedule t34 ON t34.id = t.schedule_id                                                                                             "
            + "  <if test='p1.active_tabs_index != null and p1.active_tabs_index == \"6\"'>                             "
            + "    inner join b_message t31 ON t31.serial_type = '" + SystemConstants.SERIAL_TYPE.B_MONITOR  + "'       "
            + "    and t31.serial_id = t.id                                                                             "
            + "  </if>                                                                                                  "
            + "  <if test='p1.active_tabs_index != null and p1.active_tabs_index == \"7\"'>                             "
            + "    inner join b_message t31 ON t31.serial_type = '" +  DictConstant.DICT_SYS_CODE_TYPE_B_MONITOR_UNAUDITED + "'"
            + "    and t31.serial_id = t.id                                                                             "
            + "  </if>                                                                                                  "
            + "  LEFT JOIN b_return_relation t35 ON t35.serial_id = t.id AND t35.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
            + "  AND  t35.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
            + "   ,(select @row_num:=0) t32                                                                                                                                 "
            ;

    String common_select1 = "  "
            + "     SELECT                                                                                                                                      "
            + "            t.*,                                                                                                                                 "
            + "            t13.label status_name,                                                                                                               "
            + "            t4.code as schedule_code,                                                                                                            "
            + "            ifnull(t20.type,t21.type) as in_type,                                                                                                "
            + "            ifnull(t22.type,t23.type) as out_type,                                                                                               "
            + "            ifnull(t20.qty,t21.qty) as in_qty,                                                                                                   "
            + "            ifnull(t22.qty,t23.qty) as out_qty,                                                                                                  "
            + "            ifnull(ifnull(t22.qty,t23.qty) - ifnull(t20.qty,t21.qty), 0) as qty_loss,                                                            "
            + "            case when ifnull(t20.type,t21.type) = '"+ SystemConstants.MONITOR.B_MONITOR_IN +"' then '入库' when                                   "
            + "             ifnull(t20.type,t21.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then '卸货' else '' end as in_type_name,                "
            + "            case when ifnull(t22.type,t23.type) = '"+ SystemConstants.MONITOR.B_MONITOR_OUT +"' then '出库' when                                  "
            + "             ifnull(t22.type,t23.type) = '"+ SystemConstants.MONITOR.B_MONITOR_DELIVERY +"' then '提货' else '' end as out_type_name,             "
            + "            ifnull(t20.id,t21.id) as monitor_in_id,                                                                                              "
            + "            t.in_time as monitor_finish_time,                                                                                                    "
            + "            ifnull(t22.id,t23.id) as monitor_out_id,                                                                                             "
            + "            t4.out_plan_code,                                                                                                                    "
            + "            t4.in_plan_code,                                                                                                                     "
            + "            ifnull(t6.short_name, t6.name) out_warehouse_name,                                                                                   "
            + "            t4.out_warehouse_address,                                                                                                            "
            + "            ifnull(t5.short_name, t5.name) in_warehouse_name,                                                                                    "
            + "            t4.in_warehouse_address,                                                                                                             "
            + "            ifnull(t10.contract_no,t4.contract_no) contract_no,                                                                                  "
            + "            t11.name as goods_name,                                                                                                              "
            + "            t11.spec as sku_name,                                                                                                                "
            + "            t11.pm as pm,                                                                                                                        "
            + "            t11.code as sku_code,                                                                                                                "
            + "            t7.name as customer_name,                                                                                                            "
            + "            t8.no as vehicle_no,                                                                                                                 "
            + "            t9.name as driver_name,                                                                                                              "
            + "            t9.mobile_phone as driver_mobile_phone,                                                                                              "
            + "            t1.name as c_name,                                                                                                                   "
            + "            t14.code as out_code,                                                                                                                "
            + "            t15.code as in_code,                                                                                                                 "
            + "            t16.label as out_status_name,                                                                                                        "
            + "            t17.label as in_status_name,                                                                                                         "
            + "            t14.status as out_status,                                                                                                            "
            + "            t15.status as in_status,                                                                                                             "
            + "            t2.name as u_name,                                                                                                                   "
            + "            t18.remark as cancel_remark                                                                                                          "
            + "       FROM                                                                                                                                      "
            + "  	        b_monitor t                                                                                                                         "
            + "  LEFT JOIN m_staff t1 ON t.c_id = t1.id                                                                                                         "
            + "  LEFT JOIN m_staff t2 ON t.u_id = t2.id                                                                                                         "
            + "  LEFT JOIN b_schedule t4 ON t4.id = t.schedule_id                                                                                               "
            + "  LEFT JOIN m_warehouse t5 ON t4.in_warehouse_id = t5.id                                                                                         "
            + "  LEFT JOIN m_warehouse t6 ON t4.out_warehouse_id = t6.id                                                                                        "
            + "  LEFT JOIN m_customer t7 ON t.customer_id = t7.id                                                                                               "
            + "  LEFT JOIN m_vehicle t8 ON t.vehicle_id = t8.id                                                                                                 "
            + "  LEFT JOIN m_driver t9 ON t.driver_id = t9.id                                                                                                   "
            + "  LEFT JOIN b_order t10 on t10.serial_type in ('b_in_order','b_out_order') and t4.order_id = t10.id                                             "
            + "  LEFT JOIN m_goods_spec t11 ON t4.sku_id = t11.id                                                                                               "
            + "  LEFT JOIN v_dict_info t13 ON t13.code = 'b_monitor_status' and t.status = t13.dict_value                                                       "
            + "  LEFT JOIN b_monitor_in t20 ON t20.monitor_id = t.id                                                                                            "
            + "  LEFT JOIN b_monitor_unload t21 ON t21.monitor_id = t.id                                                                                        "
            + "  LEFT JOIN b_monitor_out t22 ON t22.monitor_id = t.id                                                                                           "
            + "  LEFT JOIN b_monitor_delivery t23 ON t23.monitor_id = t.id                                                                                      "
            + "  LEFT JOIN b_out t14 on t22.out_id = t14.id                                                                                                     "
            + "  LEFT JOIN b_in t15 on t20.in_id = t15.id                                                                                                       "
            + "  LEFT JOIN v_dict_info t16 ON t16.code = '"+DictConstant.DICT_B_OUT_STATUS+"' and t14.status = t16.dict_value                                   "
            + "  LEFT JOIN v_dict_info t17 ON t17.code = '"+DictConstant.DICT_B_IN_STATUS+"' and t15.status = t17.dict_value                                    "
            + "  LEFT JOIN m_cancel t18 ON t18.serial_id = t.id and t18.serial_type = '"+SystemConstants.SERIAL_TYPE.B_MONITOR+"'                               "
            + "   "
            ;
    /**
     * 页面查询列表
     */
    @Select(" <script>   "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
            + common_select
            + "  where true                                                                                                                                                     "
            + "    and (t.status = #{p1.status,jdbcType=VARCHAR} or #{p1.status,jdbcType=VARCHAR} is null or #{p1.status,jdbcType=VARCHAR} ='')                                 "
            + "   <if test='p1.status_list != null and p1.status_list.length!=0' >                                                                                              "
            + "    and t.status in                                                                                                                                              "
            + "        <foreach collection='p1.status_list' item='item' index='index' open='(' separator=',' close=')'>                                                         "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "   <if test='p1.audit_status_list != null and p1.audit_status_list.length!=0' >                                                                                  "
            + "    and t.audit_status in                                                                                                                                        "
            + "        <foreach collection='p1.audit_status_list' item='item' index='index' open='(' separator=',' close=')'>                                                   "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "    and (t.code like concat('%',#{p1.code,jdbcType=VARCHAR},'%') or #{p1.code,jdbcType=VARCHAR} is null or #{p1.code,jdbcType=VARCHAR} = '')                     "
            + "    and (t4.code like concat('%',#{p1.schedule_code,jdbcType=VARCHAR},'%') or #{p1.schedule_code,jdbcType=VARCHAR} is null)                                      "
            + "    and (t.waybill_code like concat('%',#{p1.waybill_code,jdbcType=VARCHAR},'%') or #{p1.waybill_code,jdbcType=VARCHAR} is null)                                 "
            + "    and (concat(t7.name,t7.short_name,t7.code) like concat('%',#{p1.customer_name,jdbcType=VARCHAR},'%') or #{p1.customer_name,jdbcType=VARCHAR} is null)        "
            + "    and (concat(t8.code,t8.no) like concat('%',#{p1.vehicle_no,jdbcType=VARCHAR},'%') or #{p1.vehicle_no,jdbcType=VARCHAR} is null)                              "
            + "    and (concat(t9.name,t9.mobile_phone,t9.code) like concat('%',#{p1.driver_name,jdbcType=VARCHAR},'%') or #{p1.driver_name,jdbcType=VARCHAR} is null)          "
            + "    and (concat(ifnull(t10.contract_no,''),ifnull(t4.contract_no,'')) like concat('%',#{p1.contract_no,jdbcType=VARCHAR},'%') or #{p1.contract_no,jdbcType=VARCHAR} is null)"
            + "    and (concat(t11.name,t11.pm,t11.code,t11.spec) like concat('%',#{p1.goods_name,jdbcType=VARCHAR},'%') or #{p1.goods_name,jdbcType=VARCHAR} is null)          "
            + "    and (t4.out_type = #{p1.out_type,jdbcType=VARCHAR} or #{p1.out_type,jdbcType=VARCHAR} is null  or #{p1.out_type,jdbcType=VARCHAR} = '')                      "
            + "    and (t4.in_type = #{p1.in_type,jdbcType=VARCHAR} or #{p1.in_type,jdbcType=VARCHAR} is null or #{p1.in_type,jdbcType=VARCHAR} = '')                           "
            + "    and (concat(t6.name,t6.short_name) like concat('%',#{p1.out_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.out_warehouse_name,jdbcType=VARCHAR} is null)      "
            + "    and (concat(t5.name,t5.short_name) like concat('%',#{p1.in_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.in_warehouse_name,jdbcType=VARCHAR} is null)        "
            + "    and (t4.out_plan_code like concat('%',#{p1.out_plan_code,jdbcType=VARCHAR},'%') or #{p1.out_plan_code,jdbcType=VARCHAR} is null)                             "
            + "    and (t4.in_plan_code like concat('%',#{p1.in_plan_code,jdbcType=VARCHAR},'%') or #{p1.in_plan_code,jdbcType=VARCHAR} is null)                                "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.start_time,jdbcType=DATE} is null)              "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.over_time,jdbcType=DATE} is null)                "
            + "    and (t.settlement_status = #{p1.settlement_status,jdbcType=VARCHAR} or #{p1.settlement_status,jdbcType=VARCHAR} is null or #{p1.settlement_status,jdbcType=VARCHAR} ='')"
            + "    and (t.audit_status = #{p1.audit_status,jdbcType=VARCHAR} or #{p1.audit_status,jdbcType=VARCHAR} is null or #{p1.audit_status,jdbcType=VARCHAR} ='')         "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_start,jdbcType=DATE} is null)         "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_end,jdbcType=DATE} is null)             "
            + "    and (t.status != #{p1.un_status} or #{p1.un_status} is null or #{p1.un_status} = '')                                                                         "
            + "    and (t28.waybill_contract_no like concat('%', #{p1.waybill_contract_no}, '%') or #{p1.waybill_contract_no} is null or #{p1.waybill_contract_no} = '')        "
            + "            <if test='p1.in_warehouse_types != null and p1.in_warehouse_types.length!=0' >                                                                       "
            + "             and t5.warehouse_type in                                                                                                                            "
            + "                 <foreach collection='p1.in_warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                         "
            + "                  #{item}                                                                                                                                        "
            + "                 </foreach>                                                                                                                                      "
            + "            </if>                                                                                                                                                "
            + "            <if test='p1.out_warehouse_types != null and p1.out_warehouse_types.length!=0' >                                                                     "
            + "             and t6.warehouse_type in                                                                                                                            "
            + "                 <foreach collection='p1.out_warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                        "
            + "                  #{item}                                                                                                                                        "
            + "                 </foreach>                                                                                                                                      "
            + "            </if>                                                                                                                                                "
//            + "    and (t.settlement_status = #{p1.settlement_status} or #{p1.settlement_status} is null or #{p1.settlement_status} = '')                                       "
            + "    and (DATE_FORMAT(t.out_audit_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.out_audit_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.out_audit_start,jdbcType=DATE} is null)"
            + "    and (DATE_FORMAT(t.out_audit_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.out_audit_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.out_audit_end,jdbcType=DATE} is null)  "
            + "    and (DATE_FORMAT(t.in_audit_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_audit_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_audit_start,jdbcType=DATE} is null) "
            + "    and (DATE_FORMAT(t.in_audit_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_audit_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_audit_end,jdbcType=DATE} is null)     "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.c_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.c_time_start,jdbcType=DATE} is null)            "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.c_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.c_time_end,jdbcType=DATE} is null)                "
            + "    and (t27.name like concat('%', #{p1.out_audit_name}, '%') or #{p1.out_audit_name} is null or #{p1.out_audit_name} = '')                                      "
            + "    and (t26.name like concat('%', #{p1.in_audit_name}, '%') or #{p1.in_audit_name} is null or #{p1.in_audit_name} = '')                                         "
            + "    and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                                                                "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d 00:00:00') &gt;= DATE_FORMAT(#{p1.b_schedule_time_start,jdbcType=DATE}, '%Y-%m-%d 00:00:00' ) or #{p1.b_schedule_time_start,jdbcType=DATE} is null)                       "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d 23:59:59' ) &lt;= DATE_FORMAT(#{p1.b_schedule_time_end,jdbcType=DATE}, '%Y-%m-%d 23:59:59' ) or #{p1.b_schedule_time_end,jdbcType=DATE} is null)                "

            + "            <if test='p1.if_return_qty != null and p1.if_return_qty == 2' >                                                                                       "
            + "             and t35.qty is null                                                                                                                            "
            + "            </if>                                                                                                                                                "
            + "            <if test='p1.if_return_qty != null  and p1.if_return_qty == 1' >                                                                                      "
            + "             and t35.qty is not null                                                                                                                            "
            + "            </if>                                                                                                                                                "
            //  page页面查询条件 1=监管任务page查询 2=直采直销page查询
            + "            <if test='p1.if_page_list != null and p1.if_page_list == 1' >                                                                                       "
            + "             and t4.type not in ('"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"','"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"')                                           "
            + "            </if>                                                                                                                                               "
            // page页面查询条件 2=直采直销page查询
            + "            <if test='p1.if_page_list != null and p1.if_page_list == 2' >                                                                                         "
            + "             and t4.type in ('"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"','"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"')                                                 "
            + "             and (DATE_FORMAT(IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t.in_audit_time,t.out_audit_time) , '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.audit_time_start,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.audit_time_start,jdbcType=DATE} is null)                "
            + "             and (DATE_FORMAT(IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t.in_audit_time,t.out_audit_time) , '%Y-%m-%d' ) &lt;= DATE_FORMAT(#{p1.audit_time_end,jdbcType=DATE}, '%Y-%m-%d' )  or #{p1.audit_time_end,jdbcType=DATE} is null)                   "
            + "             and (IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t26.name,t27.name) like concat('%',#{p1.audit_name,jdbcType=VARCHAR},'%') or #{p1.audit_name,jdbcType=VARCHAR} is null)                                      "
            + "            </if>                                                                                                                                                 "
            + "     ${p1.params.dataScopeAnnotation}                                                                                                                            "
            + "   </script>   ")
    IPage<BMonitorVo> selectPage(Page page, @Param("p1") BMonitorVo searchCondition);

//    /**
//     * 页面查询列表
//     */
//    @Select(" <script>   "
//            + common_select
//            + "  where true                                                                                                                                                     "
//            + "    and (t.status = #{p1.status,jdbcType=VARCHAR} or #{p1.status,jdbcType=VARCHAR} is null or #{p1.status,jdbcType=VARCHAR} ='')                                 "
//            + "   <if test='p1.status_list != null and p1.status_list.length!=0' >                                                                                              "
//            + "    and t.status in                                                                                                                                              "
//            + "        <foreach collection='p1.status_list' item='item' index='index' open='(' separator=',' close=')'>                                                         "
//            + "         #{item}                                                                                                                                                 "
//            + "        </foreach>                                                                                                                                               "
//            + "   </if>                                                                                                                                                         "
//            + "   <if test='p1.audit_status_list != null and p1.audit_status_list.length!=0' >                                                                                  "
//            + "    and t.audit_status in                                                                                                                                        "
//            + "        <foreach collection='p1.audit_status_list' item='item' index='index' open='(' separator=',' close=')'>                                                   "
//            + "         #{item}                                                                                                                                                 "
//            + "        </foreach>                                                                                                                                               "
//            + "   </if>                                                                                                                                                         "
//            + "    and (t.code like concat('%',#{p1.code,jdbcType=VARCHAR},'%') or #{p1.code,jdbcType=VARCHAR} is null or #{p1.code,jdbcType=VARCHAR} = '')                                                         "
//            + "    and (t4.code like concat('%',#{p1.schedule_code,jdbcType=VARCHAR},'%') or #{p1.schedule_code,jdbcType=VARCHAR} is null)                                      "
//            + "    and (t.waybill_code like concat('%',#{p1.waybill_code,jdbcType=VARCHAR},'%') or #{p1.waybill_code,jdbcType=VARCHAR} is null)                                 "
//            + "    and (concat(t7.name,t7.short_name,t7.code) like concat('%',#{p1.customer_name,jdbcType=VARCHAR},'%') or #{p1.customer_name,jdbcType=VARCHAR} is null)        "
//            + "    and (concat(t8.code,t8.no) like concat('%',#{p1.vehicle_no,jdbcType=VARCHAR},'%') or #{p1.vehicle_no,jdbcType=VARCHAR} is null)                              "
//            + "    and (concat(t9.name,t9.mobile_phone,t9.code) like concat('%',#{p1.driver_name,jdbcType=VARCHAR},'%') or #{p1.driver_name,jdbcType=VARCHAR} is null)          "
//            + "    and (concat(ifnull(t10.contract_no,''),ifnull(t4.contract_no,'')) like concat('%',#{p1.contract_no,jdbcType=VARCHAR},'%') or #{p1.contract_no,jdbcType=VARCHAR} is null)                                  "
//            + "    and (concat(t11.name,t11.pm,t11.code,t11.spec) like concat('%',#{p1.goods_name,jdbcType=VARCHAR},'%') or #{p1.goods_name,jdbcType=VARCHAR} is null)          "
//            + "    and (t4.out_type = #{p1.out_type,jdbcType=VARCHAR} or #{p1.out_type,jdbcType=VARCHAR} is null  or #{p1.out_type,jdbcType=VARCHAR} = '')                      "
//            + "    and (t4.in_type = #{p1.in_type,jdbcType=VARCHAR} or #{p1.in_type,jdbcType=VARCHAR} is null or #{p1.in_type,jdbcType=VARCHAR} = '')                           "
//            + "    and (concat(t6.name,t6.short_name) like concat('%',#{p1.out_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.out_warehouse_name,jdbcType=VARCHAR} is null)      "
//            + "    and (concat(t5.name,t5.short_name) like concat('%',#{p1.in_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.in_warehouse_name,jdbcType=VARCHAR} is null)        "
//            + "    and (t4.out_plan_code like concat('%',#{p1.out_plan_code,jdbcType=VARCHAR},'%') or #{p1.out_plan_code,jdbcType=VARCHAR} is null)                             "
//            + "    and (t4.in_plan_code like concat('%',#{p1.in_plan_code,jdbcType=VARCHAR},'%') or #{p1.in_plan_code,jdbcType=VARCHAR} is null)                                "
//            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.start_time,jdbcType=DATE} is null)                "
//            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.over_time,jdbcType=DATE} is null)                  "
//            + "    and (t.settlement_status = #{p1.settlement_status,jdbcType=VARCHAR} or #{p1.settlement_status,jdbcType=VARCHAR} is null or #{p1.settlement_status,jdbcType=VARCHAR} ='')                                 "
//            + "    and (t.audit_status = #{p1.audit_status,jdbcType=VARCHAR} or #{p1.audit_status,jdbcType=VARCHAR} is null or #{p1.audit_status,jdbcType=VARCHAR} ='')         "
//            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_start,jdbcType=DATE} is null)         "
//            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_end,jdbcType=DATE} is null)             "
//            + "    and (t.status != #{p1.un_status} or #{p1.un_status} is null or #{p1.un_status} = '')"
//            + "    and (t28.waybill_contract_no like concat('%', #{p1.waybill_contract_no}, '%') or #{p1.waybill_contract_no} is null or #{p1.waybill_contract_no} = '') "
//            + "     ${p1.params.dataScopeAnnotation}                                                                                                                            "
//            // 排序
//            + "     ${p1.pageCondition.sort}                                                                                                                                    "
//            // 此处应该用${} 否则会直接输出字符串
//            + "     limit ${(p1.pageCondition.current-1)*p1.pageCondition.size},  ${p1.pageCondition.size}                                                                      "
//            + "   </script>   ")
//    List<BMonitorVo> selectPage(@Param("p1") BMonitorVo searchCondition);

    /**
     * 页面查询列表
     */
    @Select(" <script>   "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
            +" select * from (select @row_num := @row_num + 1 AS no,tab1.*,tab2.id m_id from(                                                                                                                    "
            + common_select
            + "  where true                                                                                                                                                     "
            + "    and (t.status = #{p1.status,jdbcType=VARCHAR} or #{p1.status,jdbcType=VARCHAR} is null or #{p1.status,jdbcType=VARCHAR} ='')                                 "
            + "   <if test='p1.status_list != null and p1.status_list.length!=0' >                                                                                              "
            + "    and t.status in                                                                                                                                              "
            + "        <foreach collection='p1.status_list' item='item' index='index' open='(' separator=',' close=')'>                                                         "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "   <if test='p1.audit_status_list != null and p1.audit_status_list.length!=0' >                                                                                  "
            + "    and t.audit_status in                                                                                                                                        "
            + "        <foreach collection='p1.audit_status_list' item='item' index='index' open='(' separator=',' close=')'>                                                   "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "    and (t.code like concat('%',#{p1.code,jdbcType=VARCHAR},'%') or #{p1.code,jdbcType=VARCHAR} is null)                                                         "
            + "    and (t4.code like concat('%',#{p1.schedule_code,jdbcType=VARCHAR},'%') or #{p1.schedule_code,jdbcType=VARCHAR} is null)                                      "
            + "    and (t.waybill_code like concat('%',#{p1.waybill_code,jdbcType=VARCHAR},'%') or #{p1.waybill_code,jdbcType=VARCHAR} is null)                                 "
            + "    and (concat(t7.name,t7.short_name,t7.code) like concat('%',#{p1.customer_name,jdbcType=VARCHAR},'%') or #{p1.customer_name,jdbcType=VARCHAR} is null)        "
            + "    and (concat(t8.code,t8.no) like concat('%',#{p1.vehicle_no,jdbcType=VARCHAR},'%') or #{p1.vehicle_no,jdbcType=VARCHAR} is null)                              "
            + "    and (concat(t9.name,t9.mobile_phone,t9.code) like concat('%',#{p1.driver_name,jdbcType=VARCHAR},'%') or #{p1.driver_name,jdbcType=VARCHAR} is null)          "
            + "    and (concat(ifnull(t10.contract_no,''),ifnull(t4.contract_no,''))  like concat('%',#{p1.contract_no,jdbcType=VARCHAR},'%') or #{p1.contract_no,jdbcType=VARCHAR} is null)                                  "
            + "    and (concat(t11.name,t11.pm,t11.code,t11.spec) like concat('%',#{p1.goods_name,jdbcType=VARCHAR},'%') or #{p1.goods_name,jdbcType=VARCHAR} is null)          "
            + "    and (t4.out_type = #{p1.out_type,jdbcType=VARCHAR} or #{p1.out_type,jdbcType=VARCHAR} is null  or #{p1.out_type,jdbcType=VARCHAR} = '')                      "
            + "    and (t4.in_type = #{p1.in_type,jdbcType=VARCHAR} or #{p1.in_type,jdbcType=VARCHAR} is null or #{p1.in_type,jdbcType=VARCHAR} = '')                           "
            + "    and (concat(t6.name,t6.short_name) like concat('%',#{p1.out_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.out_warehouse_name,jdbcType=VARCHAR} is null)      "
            + "    and (concat(t5.name,t5.short_name) like concat('%',#{p1.in_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.in_warehouse_name,jdbcType=VARCHAR} is null)        "
            + "    and (t4.out_plan_code like concat('%',#{p1.out_plan_code,jdbcType=VARCHAR},'%') or #{p1.out_plan_code,jdbcType=VARCHAR} is null)                             "
            + "    and (t4.in_plan_code like concat('%',#{p1.in_plan_code,jdbcType=VARCHAR},'%') or #{p1.in_plan_code,jdbcType=VARCHAR} is null)                                "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.start_time,jdbcType=DATE} is null)                "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.over_time,jdbcType=DATE} is null)                  "
            + "    and (t.settlement_status = #{p1.settlement_status,jdbcType=VARCHAR} or #{p1.settlement_status,jdbcType=VARCHAR} is null or #{p1.settlement_status,jdbcType=VARCHAR} ='')                                 "
            + "    and (t.audit_status = #{p1.audit_status,jdbcType=VARCHAR} or #{p1.audit_status,jdbcType=VARCHAR} is null or #{p1.audit_status,jdbcType=VARCHAR} ='')                                 "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_start,jdbcType=DATE} is null)         "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_end,jdbcType=DATE} is null)             "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.b_schedule_time_start,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_start,jdbcType=DATE} is null)                       "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d' ) &lt;= DATE_FORMAT(#{p1.b_schedule_time_end,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_end,jdbcType=DATE} is null)                "
            //  page页面查询条件 1=监管任务page查询 2=直采直销page查询
            + "            <if test='p1.if_page_list != null and p1.if_page_list == 1' >                                                                                       "
            + "             and t4.type not in ('"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"','"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"')                                           "
            + "            </if>                                                                                                                                               "
            // page页面查询条件 2=直采直销page查询
            + "            <if test='p1.if_page_list != null and p1.if_page_list == 2' >                                                                                         "
            + "             and t4.type in ('"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"','"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"')                                                 "
            + "             and (DATE_FORMAT(IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t.in_audit_time,t.out_audit_time) , '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.audit_time_start,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.audit_time_start,jdbcType=DATE} is null)                "
            + "             and (DATE_FORMAT(IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t.in_audit_time,t.out_audit_time) , '%Y-%m-%d' ) &lt;= DATE_FORMAT(#{p1.audit_time_end,jdbcType=DATE}, '%Y-%m-%d' )  or #{p1.audit_time_end,jdbcType=DATE} is null)                   "
            + "             and (IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t26.name,t27.name) like concat('%',#{p1.audit_name,jdbcType=VARCHAR},'%') or #{p1.audit_name,jdbcType=VARCHAR} is null)                                      "
            + "            </if>                                                                                                                                                 "
            + "     ${p1.params.dataScopeAnnotation}                                                                                                                            "
            + " ) tab1                                                                                                                                                           "
            + "     inner join b_monitor tab2 on  tab1.id = tab2.id                                                                                                             "
            + " ,(select @row_num:=0) tab3                                                                                                                                       "
            + "     ${p1.sort_sql}                                                                                                                                     "
            + "     limit 500 )tt                                                                                                                                              "
            + "    where (m_id = #{p1.id,jdbcType=INTEGER} or #{p1.id,jdbcType=INTEGER} is null)                                                                             "
            + "    and (no =  #{p1.no,jdbcType=INTEGER} or #{p1.no,jdbcType=INTEGER} is null)                                                                                "
            + "   </script>")
    BMonitorVo getMonitor(@Param("p1") BMonitorVo searchCondition);

    @Select(" <script> "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
            +"	SELECT                                                                                                                                                          "
            +"		count( * ) c                                                                                                                                                "
            +"	FROM                                                                                                                                                            "
            +"		b_monitor t                                                                                                                                                 "
            +"		LEFT JOIN b_schedule t4 ON t4.id = t.schedule_id                                                                                                            "
            +"		LEFT JOIN m_warehouse t5 ON t4.in_warehouse_id = t5.id                                                                                                      "
            +"		LEFT JOIN m_warehouse t6 ON t4.out_warehouse_id = t6.id                                                                                                     "
            +"		LEFT JOIN m_customer t7 ON t.customer_id = t7.id                                                                                                            "
            +"		LEFT JOIN m_vehicle t8 ON t.vehicle_id = t8.id                                                                                                              "
            +"		LEFT JOIN m_driver t9 ON t.driver_id = t9.id                                                                                                                "
            +"		LEFT JOIN b_order t10 ON t10.serial_type IN ( 'b_in_order', 'b_out_order' )                                                                                 "
            +"		AND t4.order_id = t10.id                                                                                                                                    "
            +"		LEFT JOIN m_goods_spec t11 ON t4.sku_id = t11.id                                                                                                            "
            + "     LEFT JOIN b_schedule_info t28 ON t4.id = t28.schedule_id                                                                                                    "
            + "  LEFT JOIN m_staff t26 ON t.in_audit_id = t26.id                                                                                                                "
            + "  LEFT JOIN m_staff t27 ON t.out_audit_id = t27.id                                                                                                               "
            + "  LEFT JOIN m_container t30 ON t30.id = t.container_id                                                                                                           "
            + "  LEFT JOIN b_schedule t34 ON t34.id = t.schedule_id                                                                                             "
            + "  <if test='p1.active_tabs_index != null and p1.active_tabs_index == \"6\"'>                             "
            + "    inner join b_message t31 ON t31.serial_type = '" + SystemConstants.SERIAL_TYPE.B_MONITOR  + "'       "
            + "    and t31.serial_id = t.id                                                                             "
            + "  </if>                                                                                                  "
            + "  <if test='p1.active_tabs_index != null and p1.active_tabs_index == \"7\"'>                             "
            + "    inner join b_message t31 ON t31.serial_type = '" +  DictConstant.DICT_SYS_CODE_TYPE_B_MONITOR_UNAUDITED + "'"
            + "    and t31.serial_id = t.id                                                                             "
            + "  </if>                                                                                                  "
            + "  <if test='p1.active_tabs_index != null and p1.active_tabs_index == \"8\"'>                             "
            + "    inner join b_message t31 ON t31.serial_type = '" +  DictConstant.DICT_SYS_CODE_TYPE_M_MONITOR_LOSS + "'"
            + "    and t31.serial_id = t.id                                                                             "
            + "  </if>                                                                                                  "
            + "  LEFT JOIN b_return_relation t35 ON t35.serial_id = t.id AND t35.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
            + "  AND  t35.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
            + "  where true                                                                                                                                                     "
            + "    and (t.status = #{p1.status,jdbcType=VARCHAR} or #{p1.status,jdbcType=VARCHAR} is null or #{p1.status,jdbcType=VARCHAR} ='')                                 "
            + "   <if test='p1.status_list != null and p1.status_list.length!=0' >                                                                                              "
            + "    and t.status in                                                                                                                                              "
            + "        <foreach collection='p1.status_list' item='item' index='index' open='(' separator=',' close=')'>                                                         "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "   <if test='p1.audit_status_list != null and p1.audit_status_list.length!=0' >                                                                                  "
            + "    and t.audit_status in                                                                                                                                        "
            + "        <foreach collection='p1.audit_status_list' item='item' index='index' open='(' separator=',' close=')'>                                                   "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "    and (t.code like concat('%',#{p1.code,jdbcType=VARCHAR},'%') or #{p1.code,jdbcType=VARCHAR} is null or #{p1.code,jdbcType=VARCHAR} = '')                     "
            + "    and (t4.code like concat('%',#{p1.schedule_code,jdbcType=VARCHAR},'%') or #{p1.schedule_code,jdbcType=VARCHAR} is null)                                      "
            + "    and (t.waybill_code like concat('%',#{p1.waybill_code,jdbcType=VARCHAR},'%') or #{p1.waybill_code,jdbcType=VARCHAR} is null)                                 "
            + "    and (concat(t7.name,t7.short_name,t7.code) like concat('%',#{p1.customer_name,jdbcType=VARCHAR},'%') or #{p1.customer_name,jdbcType=VARCHAR} is null)        "
            + "    and (concat(t8.code,t8.no) like concat('%',#{p1.vehicle_no,jdbcType=VARCHAR},'%') or #{p1.vehicle_no,jdbcType=VARCHAR} is null)                              "
            + "    and (concat(t9.name,t9.mobile_phone,t9.code) like concat('%',#{p1.driver_name,jdbcType=VARCHAR},'%') or #{p1.driver_name,jdbcType=VARCHAR} is null)          "
            + "    and (concat(ifnull(t10.contract_no,''),ifnull(t4.contract_no,'')) like concat('%',#{p1.contract_no,jdbcType=VARCHAR},'%') or #{p1.contract_no,jdbcType=VARCHAR} is null)"
            + "    and (concat(t11.name,t11.pm,t11.code,t11.spec) like concat('%',#{p1.goods_name,jdbcType=VARCHAR},'%') or #{p1.goods_name,jdbcType=VARCHAR} is null)          "
            + "    and (t4.out_type = #{p1.out_type,jdbcType=VARCHAR} or #{p1.out_type,jdbcType=VARCHAR} is null  or #{p1.out_type,jdbcType=VARCHAR} = '')                      "
            + "    and (t4.in_type = #{p1.in_type,jdbcType=VARCHAR} or #{p1.in_type,jdbcType=VARCHAR} is null or #{p1.in_type,jdbcType=VARCHAR} = '')                           "
            + "    and (concat(t6.name,t6.short_name) like concat('%',#{p1.out_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.out_warehouse_name,jdbcType=VARCHAR} is null)      "
            + "    and (concat(t5.name,t5.short_name) like concat('%',#{p1.in_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.in_warehouse_name,jdbcType=VARCHAR} is null)        "
            + "    and (t4.out_plan_code like concat('%',#{p1.out_plan_code,jdbcType=VARCHAR},'%') or #{p1.out_plan_code,jdbcType=VARCHAR} is null)                             "
            + "    and (t4.in_plan_code like concat('%',#{p1.in_plan_code,jdbcType=VARCHAR},'%') or #{p1.in_plan_code,jdbcType=VARCHAR} is null)                                "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.start_time,jdbcType=DATE} is null)              "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.over_time,jdbcType=DATE} is null)                "
            + "    and (t.settlement_status = #{p1.settlement_status,jdbcType=VARCHAR} or #{p1.settlement_status,jdbcType=VARCHAR} is null or #{p1.settlement_status,jdbcType=VARCHAR} ='')"
            + "    and (t.audit_status = #{p1.audit_status,jdbcType=VARCHAR} or #{p1.audit_status,jdbcType=VARCHAR} is null or #{p1.audit_status,jdbcType=VARCHAR} ='')         "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_start,jdbcType=DATE} is null)         "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_end,jdbcType=DATE} is null)             "
            + "    and (t.status != #{p1.un_status} or #{p1.un_status} is null or #{p1.un_status} = '')                                                                         "
            + "    and (t28.waybill_contract_no like concat('%', #{p1.waybill_contract_no}, '%') or #{p1.waybill_contract_no} is null or #{p1.waybill_contract_no} = '')        "
            + "            <if test='p1.in_warehouse_types != null and p1.in_warehouse_types.length!=0' >                                                                       "
            + "             and t5.warehouse_type in                                                                                                                            "
            + "                 <foreach collection='p1.in_warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                         "
            + "                  #{item}                                                                                                                                        "
            + "                 </foreach>                                                                                                                                      "
            + "            </if>                                                                                                                                                "
            + "            <if test='p1.out_warehouse_types != null and p1.out_warehouse_types.length!=0' >                                                                     "
            + "             and t6.warehouse_type in                                                                                                                            "
            + "                 <foreach collection='p1.out_warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                        "
            + "                  #{item}                                                                                                                                        "
            + "                 </foreach>                                                                                                                                      "
            + "            </if>                                                                                                                                                "
//            + "    and (t.settlement_status = #{p1.settlement_status} or #{p1.settlement_status} is null or #{p1.settlement_status} = '')                                       "
            + "    and (DATE_FORMAT(t.out_audit_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.out_audit_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.out_audit_start,jdbcType=DATE} is null)"
            + "    and (DATE_FORMAT(t.out_audit_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.out_audit_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.out_audit_end,jdbcType=DATE} is null)  "
            + "    and (DATE_FORMAT(t.in_audit_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_audit_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_audit_start,jdbcType=DATE} is null) "
            + "    and (DATE_FORMAT(t.in_audit_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_audit_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_audit_end,jdbcType=DATE} is null)     "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.c_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.c_time_start,jdbcType=DATE} is null)            "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.c_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.c_time_end,jdbcType=DATE} is null)                "
            + "    and (t27.name like concat('%', #{p1.out_audit_name}, '%') or #{p1.out_audit_name} is null or #{p1.out_audit_name} = '')                                      "
            + "    and (t26.name like concat('%', #{p1.in_audit_name}, '%') or #{p1.in_audit_name} is null or #{p1.in_audit_name} = '')                                         "
            + "    and (t30.code like concat('%', #{p1.container_code}, '%') or #{p1.container_code} is null or #{p1.container_code} = '')                                      "
            + "    and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                                                        "
            + "    and (t.is_sync = #{p1.is_sync,jdbcType=VARCHAR} or #{p1.is_sync,jdbcType=VARCHAR} is null or #{p1.is_sync,jdbcType=VARCHAR} ='')                             "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.b_schedule_time_start,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_start,jdbcType=DATE} is null)                       "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d' ) &lt;= DATE_FORMAT(#{p1.b_schedule_time_end,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_end,jdbcType=DATE} is null)                "
            + "            <if test='p1.if_return_qty != null and p1.if_return_qty == 2' >                                                                                       "
            + "             and t35.qty is null                                                                                                                            "
            + "            </if>                                                                                                                                                "
            + "            <if test='p1.if_return_qty != null  and p1.if_return_qty == 1' >                                                                                      "
            + "             and t35.qty is not null                                                                                                                            "
            + "            </if>                                                                                                                                                "

            //  page页面查询条件 1=监管任务page查询 2=直采直销page查询
            + "            <if test='p1.if_page_list != null and p1.if_page_list == 1' >                                                                                       "
            + "             and t4.type not in ('"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"','"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"')                                           "
            + "            </if>                                                                                                                                               "

            // page页面查询条件 2=直采直销page查询
            + "            <if test='p1.if_page_list != null and p1.if_page_list == 2' >                                                                                         "
            + "             and t4.type in ('"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"','"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"')                                                 "
            + "             and (DATE_FORMAT(IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t.in_audit_time,t.out_audit_time) , '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.audit_time_start,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.audit_time_start,jdbcType=DATE} is null)                "
            + "             and (DATE_FORMAT(IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t.in_audit_time,t.out_audit_time) , '%Y-%m-%d' ) &lt;= DATE_FORMAT(#{p1.audit_time_end,jdbcType=DATE}, '%Y-%m-%d' )  or #{p1.audit_time_end,jdbcType=DATE} is null)                   "
            + "             and (IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t26.name,t27.name) like concat('%',#{p1.audit_name,jdbcType=VARCHAR},'%') or #{p1.audit_name,jdbcType=VARCHAR} is null)                                      "
            + "            </if>                                                                                                                                                 "

            + "     ${p1.params.dataScopeAnnotation}                                                                                                                            "
            +"     </script>                                                                                                                                                    "
    )
    Long selectPageMyCount(@Param("p1") BMonitorVo searchCondition);

    /**
     * 页面查询列表
     */
    @Select(" <script>   "
            + common_select
            + "  where true                                                                                                                                                     "
            + "    and (t.status = #{p1.status,jdbcType=VARCHAR} or #{p1.status,jdbcType=VARCHAR} is null or #{p1.status,jdbcType=VARCHAR} ='')                                 "
            + "   <if test='p1.status_list != null and p1.status_list.length!=0' >                                                                                              "
            + "    and t.status in                                                                                                                                              "
            + "        <foreach collection='p1.status_list' item='item' index='index' open='(' separator=',' close=')'>                                                         "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "    and (t.code like concat('%',#{p1.code,jdbcType=VARCHAR},'%') or #{p1.code,jdbcType=VARCHAR} is null)                                                         "
            + "    and (t4.code like concat('%',#{p1.schedule_code,jdbcType=VARCHAR},'%') or #{p1.schedule_code,jdbcType=VARCHAR} is null)                                      "
            + "    and (t.waybill_code like concat('%',#{p1.waybill_code,jdbcType=VARCHAR},'%') or #{p1.waybill_code,jdbcType=VARCHAR} is null)                                 "
            + "    and (concat(t7.name,t7.short_name,t7.code) like concat('%',#{p1.customer_name,jdbcType=VARCHAR},'%') or #{p1.customer_name,jdbcType=VARCHAR} is null)        "
            + "    and (concat(t8.code,t8.no) like concat('%',#{p1.vehicle_no,jdbcType=VARCHAR},'%') or #{p1.vehicle_no,jdbcType=VARCHAR} is null)                              "
            + "    and (concat(t9.name,t9.mobile_phone,t9.code) like concat('%',#{p1.driver_name,jdbcType=VARCHAR},'%') or #{p1.driver_name,jdbcType=VARCHAR} is null)          "
            + "    and (concat(ifnull(t10.contract_no,''),ifnull(t4.contract_no,''))  like concat('%',#{p1.contract_no,jdbcType=VARCHAR},'%') or #{p1.contract_no,jdbcType=VARCHAR} is null)                                  "
            + "    and (concat(t11.name,t11.pm,t11.code,t11.spec) like concat('%',#{p1.goods_name,jdbcType=VARCHAR},'%') or #{p1.goods_name,jdbcType=VARCHAR} is null)          "
            + "    and (t4.out_type = #{p1.out_type,jdbcType=VARCHAR} or #{p1.out_type,jdbcType=VARCHAR} is null  or #{p1.out_type,jdbcType=VARCHAR} = '')                      "
            + "    and (t4.in_type = #{p1.in_type,jdbcType=VARCHAR} or #{p1.in_type,jdbcType=VARCHAR} is null or #{p1.in_type,jdbcType=VARCHAR} = '')                           "
            + "    and (concat(t6.name,t6.short_name) like concat('%',#{p1.out_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.out_warehouse_name,jdbcType=VARCHAR} is null)      "
            + "    and (concat(t5.name,t5.short_name) like concat('%',#{p1.in_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.in_warehouse_name,jdbcType=VARCHAR} is null)        "
            + "    and (t4.out_plan_code like concat('%',#{p1.out_plan_code,jdbcType=VARCHAR},'%') or #{p1.out_plan_code,jdbcType=VARCHAR} is null)                             "
            + "    and (t4.in_plan_code like concat('%',#{p1.in_plan_code,jdbcType=VARCHAR},'%') or #{p1.in_plan_code,jdbcType=VARCHAR} is null)                                "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.start_time,jdbcType=DATE} is null)                "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.over_time,jdbcType=DATE} is null)                  "
            + "    and (t30.code like concat('%', #{p1.container_code}, '%') or #{p1.container_code} is null or #{p1.container_code} = '')                                      "
            + "    and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                                                        "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.b_schedule_time_start,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_start,jdbcType=DATE} is null)                       "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d' ) &lt;= DATE_FORMAT(#{p1.b_schedule_time_end,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_end,jdbcType=DATE} is null)                "
            + "   </script>   ")
    List<BMonitorVo> selectLists(@Param("p1") BMonitorVo searchCondition);

    /**
     * 页面导出列表
     */
    @Select(" <script>   "
            + common_select_export
            + "   where true                                                                                            "
            + "   <if test='p1.ids != null and p1.ids.size!=0' >                                                                "
            + "    and t.id in                                                                                          "
            + "        <foreach collection='p1.ids' item='item' index='index' open='(' separator=',' close=')'>             "
            + "         #{item,jdbcType=INTEGER}                                                                     "
            + "        </foreach>                                                                                       "
            + "   </if>                                                                                                 "
            + "    </script>    ")
    List<BMonitorExportVo> selectExportList(@Param("p1") BMonitorVo searchCondition);

    /**
     * 页面查询列表
     */
    @Select(" <script>   "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
            + common_select_export
            + "  where true                                                                                                                                                     "
            + "    and (t.status = #{p1.status,jdbcType=VARCHAR} or #{p1.status,jdbcType=VARCHAR} is null or #{p1.status,jdbcType=VARCHAR} ='')                                 "
            + "   <if test='p1.status_list != null and p1.status_list.length!=0' >                                                                                              "
            + "    and t.status in                                                                                                                                              "
            + "        <foreach collection='p1.status_list' item='item' index='index' open='(' separator=',' close=')'>                                                         "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "   <if test='p1.audit_status_list != null and p1.audit_status_list.length!=0' >                                                                                  "
            + "    and t.audit_status in                                                                                                                                        "
            + "        <foreach collection='p1.audit_status_list' item='item' index='index' open='(' separator=',' close=')'>                                                   "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "  <if test='p1.active_tabs_index != null and p1.active_tabs_index == \"8\"'>                                                                                     "
            + "    inner join b_message t31 ON t31.serial_type = '" +  DictConstant.DICT_SYS_CODE_TYPE_M_MONITOR_LOSS + "'                                                      "
            + "    and t31.serial_id = t.id                                                                                                                                     "
            + "  </if>                                                                                                                                                          "
            + "    and (t.code like concat('%',#{p1.code,jdbcType=VARCHAR},'%') or #{p1.code,jdbcType=VARCHAR} is null or #{p1.code,jdbcType=VARCHAR} = '')                     "
            + "    and (t4.code like concat('%',#{p1.schedule_code,jdbcType=VARCHAR},'%') or #{p1.schedule_code,jdbcType=VARCHAR} is null)                                      "
            + "    and (t.waybill_code like concat('%',#{p1.waybill_code,jdbcType=VARCHAR},'%') or #{p1.waybill_code,jdbcType=VARCHAR} is null)                                 "
            + "    and (concat(t7.name,t7.short_name,t7.code) like concat('%',#{p1.customer_name,jdbcType=VARCHAR},'%') or #{p1.customer_name,jdbcType=VARCHAR} is null)        "
            + "    and (concat(t8.code,t8.no) like concat('%',#{p1.vehicle_no,jdbcType=VARCHAR},'%') or #{p1.vehicle_no,jdbcType=VARCHAR} is null)                              "
            + "    and (concat(t9.name,t9.mobile_phone,t9.code) like concat('%',#{p1.driver_name,jdbcType=VARCHAR},'%') or #{p1.driver_name,jdbcType=VARCHAR} is null)          "
            + "    and (concat(ifnull(t10.contract_no,''),ifnull(t4.contract_no,'')) like concat('%',#{p1.contract_no,jdbcType=VARCHAR},'%') or #{p1.contract_no,jdbcType=VARCHAR} is null)                                  "
            + "    and (concat(t11.name,t11.pm,t11.code,t11.spec) like concat('%',#{p1.goods_name,jdbcType=VARCHAR},'%') or #{p1.goods_name,jdbcType=VARCHAR} is null)          "
            + "    and (t4.out_type = #{p1.out_type,jdbcType=VARCHAR} or #{p1.out_type,jdbcType=VARCHAR} is null  or #{p1.out_type,jdbcType=VARCHAR} = '')                      "
            + "    and (t4.in_type = #{p1.in_type,jdbcType=VARCHAR} or #{p1.in_type,jdbcType=VARCHAR} is null or #{p1.in_type,jdbcType=VARCHAR} = '')                           "
            + "    and (concat(t6.name,t6.short_name) like concat('%',#{p1.out_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.out_warehouse_name,jdbcType=VARCHAR} is null)      "
            + "    and (concat(t5.name,t5.short_name) like concat('%',#{p1.in_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.in_warehouse_name,jdbcType=VARCHAR} is null)        "
            + "    and (t4.out_plan_code like concat('%',#{p1.out_plan_code,jdbcType=VARCHAR},'%') or #{p1.out_plan_code,jdbcType=VARCHAR} is null)                             "
            + "    and (t4.in_plan_code like concat('%',#{p1.in_plan_code,jdbcType=VARCHAR},'%') or #{p1.in_plan_code,jdbcType=VARCHAR} is null)                                "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.start_time,jdbcType=DATE} is null)                "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.over_time,jdbcType=DATE} is null)                  "
            + "    and (t.settlement_status = #{p1.settlement_status,jdbcType=VARCHAR} or #{p1.settlement_status,jdbcType=VARCHAR} is null or #{p1.settlement_status,jdbcType=VARCHAR} ='')                                 "
            + "    and (t.audit_status = #{p1.audit_status,jdbcType=VARCHAR} or #{p1.audit_status,jdbcType=VARCHAR} is null or #{p1.audit_status,jdbcType=VARCHAR} ='')         "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_start,jdbcType=DATE} is null)         "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_end,jdbcType=DATE} is null)             "
            + "    and (t.status != #{p1.un_status} or #{p1.un_status} is null or #{p1.un_status} = '')"
            + "    and (t28.waybill_contract_no like concat('%', #{p1.waybill_contract_no}, '%') or #{p1.waybill_contract_no} is null or #{p1.waybill_contract_no} = '') "
            + "            <if test='p1.in_warehouse_types != null and p1.in_warehouse_types.length!=0' >                                                                       "
            + "             and t5.warehouse_type in                                                                                                                            "
            + "                 <foreach collection='p1.in_warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                         "
            + "                  #{item}                                                                                                                                        "
            + "                 </foreach>                                                                                                                                      "
            + "            </if>                                                                                                                                                "
            + "            <if test='p1.out_warehouse_types != null and p1.out_warehouse_types.length!=0' >                                                                     "
            + "             and t6.warehouse_type in                                                                                                                            "
            + "                 <foreach collection='p1.out_warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                        "
            + "                  #{item}                                                                                                                                        "
            + "                 </foreach>                                                                                                                                      "
            + "            </if>                                                                                                                                                "
//            + "    and (t.settlement_status = #{p1.settlement_status} or #{p1.settlement_status} is null or #{p1.settlement_status} = '')                                       "
            + "    and (DATE_FORMAT(t.out_audit_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.out_audit_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.out_audit_start,jdbcType=DATE} is null)"
            + "    and (DATE_FORMAT(t.out_audit_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.out_audit_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.out_audit_end,jdbcType=DATE} is null)  "
            + "    and (DATE_FORMAT(t.in_audit_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_audit_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_audit_start,jdbcType=DATE} is null) "
            + "    and (DATE_FORMAT(t.in_audit_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_audit_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_audit_end,jdbcType=DATE} is null)     "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.c_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.c_time_start,jdbcType=DATE} is null)            "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.c_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.c_time_end,jdbcType=DATE} is null)                "
            + "    and (t27.name like concat('%', #{p1.out_audit_name}, '%') or #{p1.out_audit_name} is null or #{p1.out_audit_name} = '')                                      "
            + "    and (t26.name like concat('%', #{p1.in_audit_name}, '%') or #{p1.in_audit_name} is null or #{p1.in_audit_name} = '')                                         "
            + "    and (t30.code like concat('%', #{p1.container_code}, '%') or #{p1.container_code} is null or #{p1.container_code} = '')                                      "
            + "    and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                                                        "
            + "    and (t.is_sync = #{p1.is_sync,jdbcType=VARCHAR} or #{p1.is_sync,jdbcType=VARCHAR} is null or #{p1.is_sync,jdbcType=VARCHAR} ='')                             "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.b_schedule_time_start,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_start,jdbcType=DATE} is null)                       "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d' ) &lt;= DATE_FORMAT(#{p1.b_schedule_time_end,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_end,jdbcType=DATE} is null)                "
            + "            <if test='p1.if_return_qty != null and p1.if_return_qty == 2' >                                                                                       "
            + "             and t35.qty is null                                                                                                                            "
            + "            </if>                                                                                                                                                "
            + "            <if test='p1.if_return_qty != null  and p1.if_return_qty == 1' >                                                                                      "
            + "             and t35.qty is not null                                                                                                                            "
            + "            </if>                                                                                                                                                "
            + "     ${p1.params.dataScopeAnnotation}                                                                                                                            "
            + "   </script>   ")
    List<BMonitorExportVo> selectExportAllList(@Param("p1") BMonitorVo searchCondition);

    /**
     * 调度单id查询监管任务
     */
//    @Select("    "
//            + "     SELECT                                                                                              "
//            + "            t.*,                                                                                         "
//            + "            t3.id as monitor_in_id,                                                                      "
//            + "            t3.u_time as monitor_finish_time,                                                            "
//            + "            t11.id as monitor_out_id,                                                                    "
//            + "            t4.code as schedule_code,                                                                    "
//            + "            t4.out_plan_code,                                                                            "
//            + "            t6.name out_warehouse_name,                                                                  "
//            + "            t4.out_warehouse_address,                                                                    "
//            + "            t5.name in_warehouse_name,                                                                   "
//            + "            t4.in_warehouse_address,                                                                     "
//            + "            ifnull(t10.contract_no,t4.contract_no) contract_no,                                          "
//            + "            t12.name as goods_name,                                                                      "
//            + "            t7.name as customer_name,                                                                    "
//            + "            t8.no as vehicle_no,                                                                         "
//            + "            t9.name as driver_name,                                                                      "
//            + "            t9.mobile_phone as driver_mobile_phone,                                                      "
//            + "            ifnull(t3.status,t11.status) as status,                                                      "
//            + "            t1.name as c_name,                                                                           "
//            + "            t2.name as u_name                                                                            "
//            + "       FROM                                                                                              "
//            + "  	       b_monitor t                                                                                  "
//            + "  LEFT JOIN m_staff t1 ON t.c_id = t1.id                                                                 "
//            + "  LEFT JOIN m_staff t2 ON t.u_id = t2.id                                                                 "
//            + "  LEFT JOIN b_monitor_in t3 ON t.id = t3.monitor_id                                                      "
//            + "  LEFT JOIN b_schedule t4 ON t4.id = t.schedule_id                                                       "
//            + "  LEFT JOIN m_warehouse t5 ON t4.in_warehouse_id = t5.id                                                 "
//            + "  LEFT JOIN m_warehouse t6 ON t4.out_warehouse_id = t6.id                                                "
//            + "  LEFT JOIN m_customer t7 ON t.customer_id = t7.id                                                       "
//            + "  LEFT JOIN m_vehicle t8 ON t.vehicle_id = t8.id                                                         "
//            + "  LEFT JOIN m_driver t9 ON t.driver_id = t9.id                                                           "
//
//            + "  LEFT JOIN (                                                                                                             "
//            + "		SELECT                                                                                                               "
//            + "			t1.id,t2.contract_no                                                                                             "
//            + "		FROM                                                                                                                 "
//            + "			b_order t1                                                                                                       "
//            + "			JOIN b_in_order t2 ON t1.serial_id = t2.id                                                                       "
//            + "			AND t1.serial_type = 'b_in_order'                                                                                "
//            + "			union all                                                                                                        "
//            + "		SELECT                                                                                                               "
//            + "			t1.id,t2.contract_no                                                                                             "
//            + "		FROM                                                                                                                 "
//            + "			b_order t1                                                                                                       "
//            + "			JOIN b_out_order t2 ON t1.serial_id = t2.id                                                                      "
//            + "			AND t1.serial_type = 'b_out_order'                                                                               "
//            + "     )t10 on t4.order_id = t10.id                                                                                         "
//
//            + "  LEFT JOIN b_monitor_out t11 ON t.id = t11.monitor_id                                                   "
//            + "  LEFT JOIN m_goods_spec t12 ON t4.sku_id = t12.id                                                       "
//            + "  where true                                                                                             "
//            + "         and (t4.id =  #{p1,jdbcType=INTEGER} or #{p1,jdbcType=INTEGER} is null)                         "
//            + "      ")
//    List<AppBMonitorVo> selectByScheduleId( @Param("p1") Integer id);


    /**
     * 调度单id查询待完成入库监管任务
     */
//    @Select("    "
//            + "     SELECT                                                             "
//            + "            t.*                                                        "
//            + "       FROM                                                             "
//            + "  	       b_monitor_in t                                                "
//            + "  LEFT JOIN m_staff t1 ON t.c_id = t1.id                                 "
//            + "  LEFT JOIN m_staff t2 ON t.u_id = t2.id                                 "
//            + "  LEFT JOIN b_monitor t3 ON t3.id = t.monitor_id                 "
//            + "  LEFT JOIN b_schedule t4 ON t4.id = t3.schedule_id                                 "
//            + "  where true                                                                                                                   "
//            + "         and t.status != '"+DictConstant.DICT_B_MONITOR_IN_STATUS_FINISH+"'          "
//            + "         and (t4.id =  #{p1,jdbcType=INTEGER} or #{p1,jdbcType=INTEGER} is null)          "
//            + "      ")
//    List<AppBMonitorInVo> selectBalanceInCount(@Param("p1") Integer id);


    /**
     * 调度单id查询待完成出库监管任务
     */
//    @Select("    "
//            + "     SELECT                                                             "
//            + "            t.*                                                        "
//            + "       FROM                                                             "
//            + "  	       b_monitor_out t                                                "
//            + "  LEFT JOIN m_staff t1 ON t.c_id = t1.id                                 "
//            + "  LEFT JOIN m_staff t2 ON t.u_id = t2.id                                 "
//            + "  LEFT JOIN b_monitor t3 ON t3.id = t.monitor_id                 "
//            + "  LEFT JOIN b_schedule t4 ON t4.id = t3.schedule_id                                 "
//            + "  where true                                                                                                                   "
//            + "         and t.status != '"+DictConstant.DICT_B_MONITOR_OUT_STATUS_FINISH+"'          "
//            + "         and (t4.id =  #{p1,jdbcType=INTEGER} or #{p1,jdbcType=INTEGER} is null)          "
//            + "      ")
//    List<AppBMonitorOutVo> selectBalanceOutCount(@Param("p1") Integer id);


    /**
     * 调度单id查询已完成监管任务
     */
//    @Select("    "
//            + "     SELECT                                                             "
//            + "            t.*                                                        "
//            + "       FROM                                                             "
//            + "  	       b_monitor t                                                "
//            + "  LEFT JOIN m_staff t1 ON t.c_id = t1.id                                 "
//            + "  LEFT JOIN m_staff t2 ON t.u_id = t2.id                                 "
//            + "  LEFT JOIN b_monitor_in t3 ON t.id = t3.monitor_id                 "
//            + "  LEFT JOIN b_schedule t4 ON t4.id = t.schedule_id                                 "
//            + "  where true                                                                                                                   "
//            + "         and t3.status = '"+DictConstant.DICT_B_MONITOR_IN_STATUS_FINISH+"'          "
//            + "         and (t4.id =  #{p1,jdbcType=INTEGER} or #{p1,jdbcType=INTEGER} is null)          "
//            + "      ")
//    List<AppBMonitorVo> selectFinishCount(@Param("p1") Integer id);

    /**
     * 查询入库数量
     */
//    @Select("                                                                                                       "
//            + "     SELECT                                                             "
//            + "            count(t1.id) as in_size                                                       "
//            + "       FROM                                                             "
//            + "  	       b_monitor t                                                  "
//            + "  	       left join b_monitor_in t1 on t.id=t1.monitor_id                                                  "
//            + "  	       left join b_monitor_out t2 on t.id=t2.monitor_id                                                  "
//            + "            LEFT JOIN b_schedule t4 ON t4.id = t.schedule_id                                 "
//            + "            LEFT JOIN m_warehouse t5 ON t4.in_warehouse_id = t5.id                                 "
//            + "            LEFT JOIN m_warehouse t6 ON t4.out_warehouse_id = t6.id                                 "
//            + "            LEFT JOIN m_vehicle t8 ON t.vehicle_id = t8.id                                 "
//            + "            LEFT JOIN m_driver t9 ON t.driver_id = t9.id                                 "
//            + "     where  true                                                                                         "
//            + "            and t1.status != '"+DictConstant.DICT_B_MONITOR_IN_STATUS_FINISH+"'          "
//            + "            and (CONCAT(t4.code,t5.name,t6.name,t8.no,t9.name)                     "
//            + "            like CONCAT ('%',#{p1.combine_search_condition,jdbcType=VARCHAR},'%') or #{p1.combine_search_condition,jdbcType=VARCHAR} is null) "
//            + "     ")
//    Integer selectInListSize(@Param("p1") AppBMonitorListSizeVo searchCondition);


    /**
     * 查询出库数量
     */
//    @Select("                                                                                                       "
//            + "     SELECT                                                             "
//            + "            count(t2.id) as out_size            "
//            + "       FROM                                                             "
//            + "  	       b_monitor t                                                  "
//            + "  	       LEFT JOIN b_monitor_in t1 on t.id=t1.monitor_id                                                  "
//            + "  	       LEFT JOIN b_monitor_out t2 on t.id=t2.monitor_id                                                  "
//            + "            LEFT JOIN b_schedule t4 ON t4.id = t.schedule_id                                 "
//            + "            LEFT JOIN m_warehouse t5 ON t4.in_warehouse_id = t5.id                                 "
//            + "            LEFT JOIN m_warehouse t6 ON t4.out_warehouse_id = t6.id                                 "
//            + "            LEFT JOIN m_vehicle t8 ON t.vehicle_id = t8.id                                 "
//            + "            LEFT JOIN m_driver t9 ON t.driver_id = t9.id                                 "
//            + "     where  true                                                                                         "
//            + "            and t2.status != '"+DictConstant.DICT_B_MONITOR_OUT_STATUS_FINISH+"'          "
//            + "            and (CONCAT(t4.code,t5.name,t6.name,t8.no,t9.name)                     "
//            + "            like CONCAT ('%',#{p1.combine_search_condition,jdbcType=VARCHAR},'%') or #{p1.combine_search_condition,jdbcType=VARCHAR} is null) "
//            + "     ")
//    Integer selectOutListSize(@Param("p1") AppBMonitorListSizeVo searchCondition);

    /**
     * id查询
     */
    @Select(" <script>   "
            + common_select
            + "  where true                                                                                                                   "
            + "    and (t.id =  #{p1,jdbcType=INTEGER} or #{p1,jdbcType=INTEGER} is null)                "
            + " </script>     ")
    BMonitorVo selectId(@Param("p1") Integer id);

    /**
     * 没有分页，按id筛选条件
     * @param searchCondition
     * @return
     */
    @Select("   <script>   "
            + common_select
            + "  where t.id in "
            + "        <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>    "
            + "         #{item.id,jdbcType=INTEGER}  "
            + "        </foreach>    "
            + "  </script>    ")
    List<BMonitorEntity> selectIdsIn(@Param("p1") List<BMonitorVo> searchCondition);


    @Select("   <script>   "

            + "	SELECT                                                                                                                                                                                                                                 "
            + "		t1.id,                                                                                                                                                                                                                             "
            + "		t1.CODE,                                                                                                                                                                                                                           "
            + "		t1.c_time,                                                                                                                                                                                                                         "
            + "		t4.NO,                                                                                                                                                                                                                             "
            + "		ifnull(f_get_file_json ( t3.one_file ) ,JSON_OBJECT()) file_1,                                                                                                                                                                     "
            + "		ifnull(f_get_file_json ( t3.two_file ) ,JSON_OBJECT()) file_2,                                                                                                                                                                     "
            + "		ifnull(f_get_file_json ( t3.fourteen_file ) ,JSON_OBJECT()) file_40,                                                                                                                                                               "
            + "		ifnull(f_get_file_json ( t3.three_file ) ,JSON_OBJECT()) file_3,                                                                                                                                                                   "
            + "		ifnull(f_get_file_json ( t3.four_file ) ,JSON_OBJECT()) file_4,                                                                                                                                                                    "
            + "		ifnull(f_get_file_json ( t3.twelve_file ) ,JSON_OBJECT()) file_38,                                                                                                                                                                 "
            + "		ifnull(f_get_file_json ( t3.thirteen_file ) ,JSON_OBJECT()) file_39,                                                                                                                                                               "
            + "		ifnull(f_get_file_json ( t3.five_file ) ,JSON_OBJECT()) file_5,                                                                                                                                                                    "
            + "		ifnull(f_get_file_json ( t3.six_file ) ,JSON_OBJECT()) file_6,                                                                                                                                                                     "
            + "		ifnull(f_get_file_json ( t3.seven_file ) ,JSON_OBJECT()) file_7,                                                                                                                                                                   "
            + "		ifnull(f_get_file_json ( t3.eight_file ) ,JSON_OBJECT()) file_8,                                                                                                                                                                   "
//            + "		ifnull(case when t6.row_count > 0 then f_get_file_json(t6.container_info ->> '$[0].one')                                                                                                                                           "
//            + "		end,JSON_OBJECT()) as file_9,                                                                                                                                                                                                      "
//            + "		ifnull(case when t6.row_count > 0 then f_get_file_json(t6.container_info ->> '$[0].two')                                                                                                                                           "
//            + "		end,JSON_OBJECT()) as file_10,                                                                                                                                                                                                     "
//            + "		ifnull(case when t6.row_count > 0 then f_get_file_json(t6.container_info ->> '$[0].three')                                                                                                                                         "
//            + "		end,JSON_OBJECT()) as file_11,                                                                                                                                                                                                     "
//            + "		ifnull(case when t6.row_count > 0 then f_get_file_json(t6.container_info ->> '$[0].four')                                                                                                                                          "
//            + "		end,JSON_OBJECT()) as file_12,                                                                                                                                                                                                     "
//            + "		ifnull(case when t6.row_count = 2 then f_get_file_json(t6.container_info ->> '$[1].one')                                                                                                                                           "
//            + "		end,JSON_OBJECT()) as file_13,                                                                                                                                                                                                     "
//            + "		ifnull(case when t6.row_count = 2 then f_get_file_json(t6.container_info ->> '$[1].two')                                                                                                                                           "
//            + "		end,JSON_OBJECT()) as file_14,                                                                                                                                                                                                     "
//            + "		ifnull(case when t6.row_count = 2 then f_get_file_json(t6.container_info ->> '$[1].three')                                                                                                                                         "
//            + "		end,JSON_OBJECT()) as file_15,                                                                                                                                                                                                     "
//            + "		ifnull(case when t6.row_count = 2 then f_get_file_json(t6.container_info ->> '$[1].four')                                                                                                                                          "
//            + "		end,JSON_OBJECT()) as file_16,                                                                                                                                                                                                     "
            + "			JSON_OBJECT( ) AS file_9,                                                                                                                  "
            + "			JSON_OBJECT( ) AS file_10,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_11,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_12,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_13,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_14,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_15,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_16,                                                                                                                 "
            + "		ifnull(f_get_file_json ( t3.nine_file ),JSON_OBJECT()) file_17,                                                                                                                                                                    "
            + "		ifnull(f_get_file_json ( t3.ten_file ),JSON_OBJECT()) file_18,                                                                                                                                                                     "
            + "		ifnull(f_get_file_json ( t3.eleven_file ),JSON_OBJECT()) file_19,                                                                                                                                                                  "
            + "		ifnull(f_get_file_json ( t2.one_file ),JSON_OBJECT()) file_20,                                                                                                                                                                     "
            + "		ifnull(f_get_file_json ( t2.two_file ),JSON_OBJECT()) file_21,                                                                                                                                                                     "
            + "		ifnull(f_get_file_json ( t2.ten_file ),JSON_OBJECT()) file_22,                                                                                                                                                                     "
            + "		ifnull(f_get_file_json ( t2.three_file ),JSON_OBJECT()) file_23,                                                                                                                                                                   "
            + "		ifnull(f_get_file_json ( t2.four_file ),JSON_OBJECT()) file_24,                                                                                                                                                                    "
            + "		ifnull(f_get_file_json ( t2.five_file ),JSON_OBJECT()) file_25,                                                                                                                                                                    "
            + "		ifnull(f_get_file_json ( t2.six_file ),JSON_OBJECT()) file_26,                                                                                                                                                                     "
//            + "		ifnull(case when t5.row_count > 0 then f_get_file_json(t5.container_info ->> '$[0].one')                                                                                                                                           "
//            + "		end,JSON_OBJECT()) as file_27,                                                                                                                                                                                                     "
//            + "		ifnull(case when t5.row_count > 0 then f_get_file_json(t5.container_info ->> '$[0].two')                                                                                                                                           "
//            + "		end,JSON_OBJECT()) as file_28,                                                                                                                                                                                                     "
//            + "		ifnull(case when t5.row_count > 0 then f_get_file_json(t5.container_info ->> '$[0].three')                                                                                                                                         "
//            + "		end,JSON_OBJECT()) as file_29,                                                                                                                                                                                                     "
//            + "		ifnull(case when t5.row_count > 0 then f_get_file_json(t5.container_info ->> '$[0].four')                                                                                                                                          "
//            + "		end,JSON_OBJECT()) as file_30,                                                                                                                                                                                                     "
//            + "		ifnull(case when t5.row_count = 2 then f_get_file_json(t5.container_info ->> '$[1].one')                                                                                                                                           "
//            + "		end,JSON_OBJECT()) as file_31,                                                                                                                                                                                                     "
//            + "		ifnull(case when t5.row_count = 2 then f_get_file_json(t5.container_info ->> '$[1].two')                                                                                                                                           "
//            + "		end,JSON_OBJECT()) as file_32,                                                                                                                                                                                                     "
//            + "		ifnull(case when t5.row_count = 2 then f_get_file_json(t5.container_info ->> '$[1].three')                                                                                                                                         "
//            + "		end ,JSON_OBJECT())as file_33,                                                                                                                                                                                                     "
//            + "		ifnull(case when t5.row_count = 2 then f_get_file_json(t5.container_info ->> '$[1].four')                                                                                                                                          "
//            + "		end,JSON_OBJECT()) as file_34,                                                                                                                                                                                                     "
            + "			JSON_OBJECT( ) AS file_27,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_28,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_29,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_30,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_31,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_32,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_33,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_34,                                                                                                                 "
            + "		ifnull(f_get_file_json ( t2.seven_file ),JSON_OBJECT()) file_35,                                                                                                                                                                   "
            + "		ifnull(f_get_file_json ( t2.eight_file ),JSON_OBJECT()) file_36,                                                                                                                                                                   "
            + "		ifnull(f_get_file_json ( t2.nine_file ),JSON_OBJECT()) file_37,                                                                                                                                                                     "

            + "		ifnull( f_get_file_json ( t2.eleven_file ), JSON_OBJECT( ) ) file_41,                                                                                                                                                              "
            + "		ifnull( f_get_file_json ( t2.twelve_file), JSON_OBJECT( ) ) file_42,                                                                                                                                                               "
            + "		ifnull( f_get_file_json ( t3.fifteen_file ) , JSON_OBJECT( ) ) file_43                                                                                                                                                             "
            + "	FROM                                                                                                                                                                                                                                   "
            + "		b_monitor t1                                                                                                                                                                                                                       "
            + "		LEFT JOIN ( SELECT 'b_monitor_in' serial_type, tab1.* FROM b_monitor_in tab1 UNION ALL SELECT 'b_monitor_unload' serial_type, tab2.* FROM b_monitor_unload tab2 ) t2 ON t2.monitor_id = t1.id                                      "
            + "		LEFT JOIN ( SELECT 'b_monitor_out' serial_type, tab1.* FROM b_monitor_out tab1 UNION ALL SELECT 'b_monitor_delivery' serial_type, tab2.* FROM b_monitor_delivery tab2 ) t3 ON t3.monitor_id = t1.id                                "
            + "		LEFT JOIN m_vehicle t4 ON t1.vehicle_id = t4.id                                                                                                                                                                                    "
            + "		LEFT JOIN (                                                                                                                                                                                                                        "
            + "		SELECT                                                                                                                                                                                                                             "
            + "		JSON_ARRAYAGG( JSON_OBJECT('row_num',tab1.row_num,                                                                                                                                                                                 "
            + "		                           'one',ifnull(tab1.file_one,-1),                                                                                                                                                                         "
            + "									 'two',ifnull(tab1.file_two,-1),                                                                                                                                                                       "
            + "									 'three',ifnull(tab1.file_three,-1),                                                                                                                                                                   "
            + "									 'four',ifnull(tab1.file_four,-1))) as container_info,                                                                                                                                                 "
            + "		JSon_length(JSON_ARRAYAGG( JSON_OBJECT('row_num',tab1.row_num))) row_count,                                                                                                                                                        "
            + "		tab1.serial_id,                                                                                                                                                                                                                    "
            + "		tab1.serial_type                                                                                                                                                                                                                   "
            + "	FROM                                                                                                                                                                                                                                   "
            + "		(                                                                                                                                                                                                                                  "
            + "	SELECT                                                                                                                                                                                                                                 "
            + "		row_number ( ) over ( PARTITION BY t1.serial_id,t1.serial_type ORDER BY t1.id) AS row_num,                                                                                                                                         "
            + "		t1.*                                                                                                                                                                                                                               "
            + "	FROM                                                                                                                                                                                                                                   "
            + "		b_container_info t1                                                                                                                                                                                                                "
            + "		where t1.serial_id is not null                                                                                                                                                                                                     "
            + "		) tab1                                                                                                                                                                                                                             "
            + "		GROUP BY tab1.serial_id,tab1.serial_type                                                                                                                                                                                           "
            + "		) t5 on t2.id = t5.serial_id and t2.serial_type = t5.serial_type                                                                                                                                                                   "
            + "		LEFT JOIN (                                                                                                                                                                                                                        "
            + "		SELECT                                                                                                                                                                                                                             "
            + "		JSON_ARRAYAGG( JSON_OBJECT('row_num',tab1.row_num,                                                                                                                                                                                 "
            + "		                           'one',ifnull(tab1.file_one,-1),                                                                                                                                                                         "
            + "									'two',ifnull(tab1.file_two,-1),                                                                                                                                                                        "
            + "									'three',ifnull(tab1.file_three,-1),                                                                                                                                                                    "
            + "									'four',ifnull(tab1.file_four,-1))) as container_info,                                                                                                                                                  "
            + "		JSon_length(JSON_ARRAYAGG( JSON_OBJECT('row_num',tab1.row_num))) row_count,                                                                                                                                                        "
            + "		tab1.serial_id,                                                                                                                                                                                                                    "
            + "		tab1.serial_type                                                                                                                                                                                                                   "
            + "	FROM                                                                                                                                                                                                                                   "
            + "		(                                                                                                                                                                                                                                  "
            + "	SELECT                                                                                                                                                                                                                                 "
            + "		row_number ( ) over ( PARTITION BY t1.serial_id,t1.serial_type ORDER BY t1.id) AS row_num,                                                                                                                                         "
            + "		t1.*                                                                                                                                                                                                                               "
            + "	FROM                                                                                                                                                                                                                                   "
            + "		b_container_info t1                                                                                                                                                                                                                "
            + "		where t1.serial_id is not null                                                                                                                                                                                                     "
            + "		) tab1                                                                                                                                                                                                                             "
            + "		GROUP BY tab1.serial_id,tab1.serial_type                                                                                                                                                                                           "
            + "		) t6 on t3.id = t6.serial_id and t3.serial_type = t6.serial_type                                                                                                                                                                   "
            + "  where t1.id in "
            + "        <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>    "
            + "         #{item.id,jdbcType=INTEGER}  "
            + "        </foreach>    "
            + "  </script>    ")
    @Results({
            @Result(property = "file_1", column = "file_1", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_2", column = "file_2", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_40", column = "file_40", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_3", column = "file_3", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_4", column = "file_4", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_38", column = "file_38", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_39", column = "file_39", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_5", column = "file_5", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_6", column = "file_6", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_7", column = "file_7", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_8", column = "file_8", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_9", column = "file_9", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_10", column = "file_10", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_11", column = "file_11", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_12", column = "file_12", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_13", column = "file_13", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_14", column = "file_14", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_15", column = "file_15", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_16", column = "file_16", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_17", column = "file_17", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_18", column = "file_18", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_19", column = "file_19", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_20", column = "file_20", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_21", column = "file_21", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_22", column = "file_22", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_23", column = "file_23", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_24", column = "file_24", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_25", column = "file_25", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_26", column = "file_26", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_27", column = "file_27", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_28", column = "file_28", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_29", column = "file_29", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_30", column = "file_30", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_31", column = "file_31", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_32", column = "file_32", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_33", column = "file_33", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_34", column = "file_34", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_35", column = "file_35", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_36", column = "file_36", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_37", column = "file_37", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_41", column = "file_41", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_42", column = "file_42", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),
            @Result(property = "file_43", column = "file_43", javaType = BMonitorFileVo.class, typeHandler = BMonitorFileVoTypeHandler.class),

    })
    List<BMonitorFileExportVo> getMonitorFiles(@Param("p1") List<BMonitorVo> searchCondition);

    @Select("     "
            + "		SELECT                                                                                                                                         "
            + "			t1.id,                                                                                                                                     "
            + "			t1.CODE,                                                                                                                                   "
            + "			t1.c_time,                                                                                                                                 "
            + "			t4.NO,                                                                                                                                     "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.one_file,t3_2.one_file) ), JSON_OBJECT( ) ) file_1,                                                  "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.two_file,t3_2.two_file) ), JSON_OBJECT( ) ) file_2,                                                  "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.fourteen_file,t3_2.fourteen_file) ), JSON_OBJECT( ) ) file_40,                                       "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.three_file,t3_2.three_file) ), JSON_OBJECT( ) ) file_3,                                              "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.four_file,t3_2.four_file) ), JSON_OBJECT( ) ) file_4,                                                "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.twelve_file,t3_2.twelve_file) ), JSON_OBJECT( ) ) file_38,                                           "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.thirteen_file,t3_2.thirteen_file) ), JSON_OBJECT( ) ) file_39,                                       "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.five_file,t3_2.five_file) ), JSON_OBJECT( ) ) file_5,                                                "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.six_file,t3_2.six_file) ), JSON_OBJECT( ) ) file_6,                                                  "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.seven_file,t3_2.seven_file) ), JSON_OBJECT( ) ) file_7,                                              "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.eight_file,t3_2.eight_file) ), JSON_OBJECT( ) ) file_8,                                              "
            + "			JSON_OBJECT( ) AS file_9,                                                                                                                  "
            + "			JSON_OBJECT( ) AS file_10,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_11,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_12,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_13,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_14,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_15,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_16,                                                                                                                 "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.nine_file,t3_2.nine_file) ), JSON_OBJECT( ) ) file_17,                                               "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.ten_file,t3_2.ten_file) ), JSON_OBJECT( ) ) file_18,                                                 "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.eleven_file,t3_2.eleven_file) ), JSON_OBJECT( ) ) file_19,                                           "
            + "			ifnull( f_get_file_json ( ifnull(t2_1.one_file,t2_2.one_file) ), JSON_OBJECT( ) ) file_20,                                                 "
            + "			ifnull( f_get_file_json ( ifnull(t2_1.two_file,t2_2.two_file )), JSON_OBJECT( ) ) file_21,                                                 "
            + "			ifnull( f_get_file_json ( ifnull(t2_1.ten_file,t2_2.ten_file )), JSON_OBJECT( ) ) file_22,                                                 "
            + "			ifnull( f_get_file_json ( ifnull(t2_1.three_file,t2_2.three_file )), JSON_OBJECT( ) ) file_23,                                             "
            + "			ifnull( f_get_file_json ( ifnull(t2_1.four_file ,t2_2.four_file)), JSON_OBJECT( ) ) file_24,                                               "
            + "			ifnull( f_get_file_json ( ifnull(t2_1.five_file,t2_2.five_file )), JSON_OBJECT( ) ) file_25,                                               "
            + "			ifnull( f_get_file_json ( ifnull(t2_1.six_file,t2_2.six_file )), JSON_OBJECT( ) ) file_26,                                                 "
            + "			JSON_OBJECT( ) AS file_27,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_28,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_29,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_30,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_31,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_32,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_33,                                                                                                                 "
            + "			JSON_OBJECT( ) AS file_34,                                                                                                                 "
            + "			ifnull( f_get_file_json ( ifnull(t2_1.seven_file,t2_2.seven_file ) ), JSON_OBJECT( ) ) file_35,                                            "
            + "			ifnull( f_get_file_json ( ifnull(t2_1.eight_file,t2_2.eight_file ) ), JSON_OBJECT( ) ) file_36,                                            "
            + "			ifnull( f_get_file_json ( ifnull(t2_1.nine_file,t2_2.nine_file ) ), JSON_OBJECT( ) ) file_37,                                              "
            + "			ifnull( f_get_file_json ( ifnull(t2_1.eleven_file,t2_2.eleven_file ) ), JSON_OBJECT( ) ) file_41,                                          "
            + "			ifnull( f_get_file_json ( ifnull(t2_1.twelve_file,t2_2.twelve_file ) ), JSON_OBJECT( ) ) file_42,                                          "
            + "			ifnull( f_get_file_json ( ifnull(t3_1.fifteen_file,t3_2.fifteen_file ) ), JSON_OBJECT( ) ) file_43                                         "

            + "		FROM                                                                                                                                           "
            + "			b_monitor t1                                                                                                                               "
            + "			LEFT JOIN ( SELECT 'b_monitor_in' serial_type, tab1.* FROM b_monitor_in tab1 ) t2_1 ON t2_1.monitor_id = t1.id                             "
            + "			LEFT JOIN ( SELECT 'b_monitor_unload' serial_type, tab2.* FROM b_monitor_unload tab2 ) t2_2 ON t2_2.monitor_id = t1.id                     "
            + "			LEFT JOIN ( SELECT 'b_monitor_out' serial_type, tab1.* FROM b_monitor_out tab1  ) t3_1 ON t3_1.monitor_id = t1.id                          "
            + "			LEFT JOIN ( SELECT 'b_monitor_delivery' serial_type, tab2.* FROM b_monitor_delivery tab2 ) t3_2 ON t3_2.monitor_id = t1.id                 "
            + "			LEFT JOIN m_vehicle t4 ON t1.vehicle_id = t4.id                                                                                            "
            + "     where t1.id = #{p1.id,jdbcType=INTEGER}                                                                                                        "
            + "     ")
    @Results({
            @Result(property = "file_1", column = "file_1", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_2", column = "file_2", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_40", column = "file_40", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_3", column = "file_3", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_4", column = "file_4", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_38", column = "file_38", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_39", column = "file_39", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_5", column = "file_5", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_6", column = "file_6", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_7", column = "file_7", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_8", column = "file_8", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_9", column = "file_9", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_10", column = "file_10", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_11", column = "file_11", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_12", column = "file_12", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_13", column = "file_13", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_14", column = "file_14", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_15", column = "file_15", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_16", column = "file_16", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_17", column = "file_17", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_18", column = "file_18", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_19", column = "file_19", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_20", column = "file_20", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_21", column = "file_21", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_22", column = "file_22", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_23", column = "file_23", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_24", column = "file_24", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_25", column = "file_25", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_26", column = "file_26", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_27", column = "file_27", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_28", column = "file_28", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_29", column = "file_29", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_30", column = "file_30", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_31", column = "file_31", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_32", column = "file_32", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_33", column = "file_33", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_34", column = "file_34", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_35", column = "file_35", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_36", column = "file_36", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_37", column = "file_37", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_41", column = "file_41", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_42", column = "file_42", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
            @Result(property = "file_43", column = "file_43", javaType = BMonitorPreviewFileVo.class, typeHandler = BMonitorPreviewFileVoTypeHandler.class),
    })
    BMonitorFilePreviewVo getMonitorFile(@Param("p1") BMonitorVo searchCondition);

    @Select("<script>                                                                                                                                           "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                                           "
            + "     SELECT                                                                                                                                      "
            + "            sum( case when ifnull(t20.type,t21.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0 else                              "
            + "  if(ifnull(t22.qty,t23.qty) &lt;= ifnull(t20.qty,t21.qty), 0, ifnull(ifnull(t22.qty,t23.qty) - ifnull(t20.qty,t21.qty)-ifnull(t35.qty,0), 0)) end) as qty_loss,   "
            + "            sum(ifnull(t20.qty,t21.qty)) as in_qty,                                                                                              "
            + "            sum(ifnull(t22.qty,t23.qty)) as out_qty,                                                                                             "
            + "            t33.count as sync_error_count,                                                                                                        "
            + "            sum(t35.qty) as count_return_qty                                                                                                        "
            + "       FROM                                                                                                                                      "
            + "  	        b_monitor t                                                                                                                         "
            + "  INNER JOIN b_schedule t4 ON t4.id = t.schedule_id                                                                                              "
            + "  LEFT JOIN m_warehouse t5 ON t4.in_warehouse_id = t5.id                                                                                         "
            + "  LEFT JOIN m_warehouse t6 ON t4.out_warehouse_id = t6.id                                                                                        "
            + "  LEFT JOIN m_customer t7 ON t.customer_id = t7.id                                                                                               "
            + "  LEFT JOIN m_vehicle t8 ON t.vehicle_id = t8.id                                                                                                 "
            + "  LEFT JOIN m_driver t9 ON t.driver_id = t9.id                                                                                                   "
            + "  LEFT JOIN b_order t10 on t4.order_id = t10.id                                                                                                  "
            + "  LEFT JOIN m_goods_spec t11 ON t4.sku_id = t11.id                                                                                               "
            + "  LEFT JOIN b_monitor_in t20 ON t20.monitor_id = t.id                                                                                            "
            + "  LEFT JOIN b_monitor_unload t21 ON t21.monitor_id = t.id                                                                                        "
            + "  LEFT JOIN b_monitor_out t22 ON t22.monitor_id = t.id                                                                                           "
            + "  LEFT JOIN b_monitor_delivery t23 ON t23.monitor_id = t.id                                                                                      "
            + "  LEFT JOIN b_out t14 on t22.out_id = t14.id                                                                                                     "
            + "  LEFT JOIN b_in t15 on t20.in_id = t15.id                                                                                                       "
            + "  LEFT JOIN m_staff t26 ON t.in_audit_id = t26.id                                                                                                "
            + "  LEFT JOIN m_staff t27 ON t.out_audit_id = t27.id                                                                                               "
            + "  LEFT JOIN b_schedule_info t28 ON t4.id = t28.schedule_id                                                                                       "
            + "  LEFT JOIN m_container t30 ON t30.id = t.container_id                                                                                           "
            + "  cross JOIN (select count(t32.id) count from b_monitor t32 where t32.is_sync = '"+DictConstant.DICT_B_MONITOR_IS_SYNC_2+"') t33                 "
            + "  LEFT JOIN b_schedule t34 ON t34.id = t.schedule_id                                                                                             "
            + "  <if test='p1.active_tabs_index != null and p1.active_tabs_index == \"6\"'>                             "
            + "    inner join b_message t31 ON t31.serial_type = '" + SystemConstants.SERIAL_TYPE.B_MONITOR  + "'       "
            + "    and t31.serial_id = t.id                                                                             "
            + "  </if>                                                                                                  "
            + "  <if test='p1.active_tabs_index != null and p1.active_tabs_index == \"7\"'>                             "
            + "    inner join b_message t31 ON t31.serial_type = '" +  DictConstant.DICT_SYS_CODE_TYPE_B_MONITOR_UNAUDITED + "'"
            + "    and t31.serial_id = t.id                                                                             "
            + "  </if>                                                                                                  "
            + "  <if test='p1.active_tabs_index != null and p1.active_tabs_index == \"8\"'>                             "
            + "    inner join b_message t31 ON t31.serial_type = '" +  DictConstant.DICT_SYS_CODE_TYPE_M_MONITOR_LOSS + "'"
            + "    and t31.serial_id = t.id                                                                             "
            + "  </if>                                                                                                  "
            + "  LEFT JOIN b_return_relation t35 ON t35.serial_id = t.id AND t35.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
            + "  AND  t35.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
            + "  where true                                                                                                                                                     "
            + "    and (t.status = #{p1.status,jdbcType=VARCHAR} or #{p1.status,jdbcType=VARCHAR} is null or #{p1.status,jdbcType=VARCHAR} ='')                                 "
            + "   <if test='p1.status_list != null and p1.status_list.length!=0' >                                                                                              "
            + "    and t.status in                                                                                                                                              "
            + "        <foreach collection='p1.status_list' item='item' index='index' open='(' separator=',' close=')'>                                                         "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "   <if test='p1.audit_status_list != null and p1.audit_status_list.length!=0' >                                                                                  "
            + "    and t.audit_status in                                                                                                                                        "
            + "        <foreach collection='p1.audit_status_list' item='item' index='index' open='(' separator=',' close=')'>                                                   "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "    and (t.code like concat('%',#{p1.code,jdbcType=VARCHAR},'%') or #{p1.code,jdbcType=VARCHAR} is null or #{p1.code,jdbcType=VARCHAR} = '')                     "
            + "    and (t4.code like concat('%',#{p1.schedule_code,jdbcType=VARCHAR},'%') or #{p1.schedule_code,jdbcType=VARCHAR} is null)                                      "
            + "    and (t.waybill_code like concat('%',#{p1.waybill_code,jdbcType=VARCHAR},'%') or #{p1.waybill_code,jdbcType=VARCHAR} is null)                                 "
            + "    and (concat(t7.name,t7.short_name,t7.code) like concat('%',#{p1.customer_name,jdbcType=VARCHAR},'%') or #{p1.customer_name,jdbcType=VARCHAR} is null)        "
            + "    and (concat(t8.code,t8.no) like concat('%',#{p1.vehicle_no,jdbcType=VARCHAR},'%') or #{p1.vehicle_no,jdbcType=VARCHAR} is null)                              "
            + "    and (concat(t9.name,t9.mobile_phone,t9.code) like concat('%',#{p1.driver_name,jdbcType=VARCHAR},'%') or #{p1.driver_name,jdbcType=VARCHAR} is null)          "
            + "    and (concat(ifnull(t10.contract_no,''),ifnull(t4.contract_no,'')) like concat('%',#{p1.contract_no,jdbcType=VARCHAR},'%') or #{p1.contract_no,jdbcType=VARCHAR} is null)"
            + "    and (concat(t11.name,t11.pm,t11.code,t11.spec) like concat('%',#{p1.goods_name,jdbcType=VARCHAR},'%') or #{p1.goods_name,jdbcType=VARCHAR} is null)          "
            + "    and (t4.out_type = #{p1.out_type,jdbcType=VARCHAR} or #{p1.out_type,jdbcType=VARCHAR} is null  or #{p1.out_type,jdbcType=VARCHAR} = '')                      "
            + "    and (t4.in_type = #{p1.in_type,jdbcType=VARCHAR} or #{p1.in_type,jdbcType=VARCHAR} is null or #{p1.in_type,jdbcType=VARCHAR} = '')                           "
            + "    and (concat(t6.name,t6.short_name) like concat('%',#{p1.out_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.out_warehouse_name,jdbcType=VARCHAR} is null)      "
            + "    and (concat(t5.name,t5.short_name) like concat('%',#{p1.in_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.in_warehouse_name,jdbcType=VARCHAR} is null)        "
            + "    and (t4.out_plan_code like concat('%',#{p1.out_plan_code,jdbcType=VARCHAR},'%') or #{p1.out_plan_code,jdbcType=VARCHAR} is null)                             "
            + "    and (t4.in_plan_code like concat('%',#{p1.in_plan_code,jdbcType=VARCHAR},'%') or #{p1.in_plan_code,jdbcType=VARCHAR} is null)                                "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.start_time,jdbcType=DATE} is null)              "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.over_time,jdbcType=DATE} is null)                "
            + "    and (t.settlement_status = #{p1.settlement_status,jdbcType=VARCHAR} or #{p1.settlement_status,jdbcType=VARCHAR} is null or #{p1.settlement_status,jdbcType=VARCHAR} ='')"
            + "    and (t.audit_status = #{p1.audit_status,jdbcType=VARCHAR} or #{p1.audit_status,jdbcType=VARCHAR} is null or #{p1.audit_status,jdbcType=VARCHAR} ='')         "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_start,jdbcType=DATE} is null)         "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_end,jdbcType=DATE} is null)             "
            + "    and (t.status != #{p1.un_status} or #{p1.un_status} is null or #{p1.un_status} = '')                                                                         "
            + "    and (t28.waybill_contract_no like concat('%', #{p1.waybill_contract_no}, '%') or #{p1.waybill_contract_no} is null or #{p1.waybill_contract_no} = '')        "
            + "            <if test='p1.in_warehouse_types != null and p1.in_warehouse_types.length!=0' >                                                                       "
            + "             and t5.warehouse_type in                                                                                                                            "
            + "                 <foreach collection='p1.in_warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                         "
            + "                  #{item}                                                                                                                                        "
            + "                 </foreach>                                                                                                                                      "
            + "            </if>                                                                                                                                                "
            + "            <if test='p1.out_warehouse_types != null and p1.out_warehouse_types.length!=0' >                                                                     "
            + "             and t6.warehouse_type in                                                                                                                            "
            + "                 <foreach collection='p1.out_warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                        "
            + "                  #{item}                                                                                                                                        "
            + "                 </foreach>                                                                                                                                      "
            + "            </if>                                                                                                                                                "
//            + "    and (t.settlement_status = #{p1.settlement_status} or #{p1.settlement_status} is null or #{p1.settlement_status} = '')                                       "
            + "    and (DATE_FORMAT(t.out_audit_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.out_audit_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.out_audit_start,jdbcType=DATE} is null)"
            + "    and (DATE_FORMAT(t.out_audit_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.out_audit_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.out_audit_end,jdbcType=DATE} is null)  "
            + "    and (DATE_FORMAT(t.in_audit_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_audit_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_audit_start,jdbcType=DATE} is null) "
            + "    and (DATE_FORMAT(t.in_audit_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_audit_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_audit_end,jdbcType=DATE} is null)     "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.c_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.c_time_start,jdbcType=DATE} is null)            "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.c_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.c_time_end,jdbcType=DATE} is null)                "
            + "    and (t27.name like concat('%', #{p1.out_audit_name}, '%') or #{p1.out_audit_name} is null or #{p1.out_audit_name} = '')                                      "
            + "    and (t26.name like concat('%', #{p1.in_audit_name}, '%') or #{p1.in_audit_name} is null or #{p1.in_audit_name} = '')                                         "
            + "    and (t30.code like concat('%', #{p1.container_code}, '%') or #{p1.container_code} is null or #{p1.container_code} = '')                                      "
            + "    and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                                                        "
            + "    and (t.is_sync = #{p1.is_sync,jdbcType=VARCHAR} or #{p1.is_sync,jdbcType=VARCHAR} is null or #{p1.is_sync,jdbcType=VARCHAR} ='')                             "
//            + "    and t34.status IN ('"+ DictConstant.DICT_B_SCHEDULE_STATUS_ZERO +"', '"+ DictConstant.DICT_B_SCHEDULE_STATUS_ONE +"' )                                "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.b_schedule_time_start,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_start,jdbcType=DATE} is null)                       "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d' ) &lt;= DATE_FORMAT(#{p1.b_schedule_time_end,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_end,jdbcType=DATE} is null)                "
            + "            <if test='p1.if_return_qty != null and p1.if_return_qty == 2' >                                                                                       "
            + "             and t35.qty is null                                                                                                                            "
            + "            </if>                                                                                                                                                "
            + "            <if test='p1.if_return_qty != null  and p1.if_return_qty == 1' >                                                                                      "
            + "             and t35.qty is not null                                                                                                                            "
            + "            </if>                                                                                                                                                "
            //  page页面查询条件 1=监管任务page查询 2=直采直销page查询
            + "            <if test='p1.if_page_list != null and p1.if_page_list == 1' >                                                                                       "
            + "             and t4.type not in ('"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"','"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"')                                           "
            + "            </if>                                                                                                                                               "
            // page页面查询条件 2=直采直销page查询
            + "            <if test='p1.if_page_list != null and p1.if_page_list == 2' >                                                                                         "
            + "             and t4.type in ('"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"','"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"')                                                 "
            + "             and (DATE_FORMAT(IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t.in_audit_time,t.out_audit_time) , '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.audit_time_start,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.audit_time_start,jdbcType=DATE} is null)                "
            + "             and (DATE_FORMAT(IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t.in_audit_time,t.out_audit_time) , '%Y-%m-%d' ) &lt;= DATE_FORMAT(#{p1.audit_time_end,jdbcType=DATE}, '%Y-%m-%d' )  or #{p1.audit_time_end,jdbcType=DATE} is null)                   "
            + "             and (IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t26.name,t27.name) like concat('%',#{p1.audit_name,jdbcType=VARCHAR},'%') or #{p1.audit_name,jdbcType=VARCHAR} is null)                                      "
            + "            </if>                                                                                                                                                 "

            + "     ${p1.params.dataScopeAnnotation}                                                                                                                            "
            + "</script>                                                                                                                                                        "
    )
    BMonitorSumVo selectListSum(@Param("p1") BMonitorVo searchCondition);

    /**
     * 损耗报表 and 在途报表
     *  query_type = 1. 损耗报表： 汇总监管状态为卸货完成的监管任务单
     *  query_type = 2. 在途报表： 汇总监管状态为装货完成、重车过磅、正在装货的监管任务单
     *
     * @param param
     * @return
     */
    @Select({
            " <script>                                                                                                "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + "    SELECT                                                                                     "

                    + "    <if test='p1.query_type == 1'>                                                             "
                    + "    	sum(case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
                    + "     else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty )-ifnull(t9.qty,0), 0 ) end ) AS qty,       "
                    + "    </if>                                                                                      "

                    + "    <if test='p1.query_type == 2'>                                                             "
                    + "    	sum(ifnull( t6.qty, t7.qty)) AS qty,                                                      "
                    + "    </if>                                                                                      "

                    + "    	t3.NAME AS goods_name,                                                                    "
                    + "     t3.code goods_code          ,                                                             "
                    + "     t3.id id_num                                                                              "
                    + "    FROM                                                                                       "
                    + "    	b_monitor t                                                                               "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                          "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                            "
                    + "    	LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                               "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                     "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                        "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                   "
                    + "     LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                      "
                    + "     LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "    	WHERE true                                                                                "
                    + "     AND (t3.name LIKE CONCAT('%', #{p1.goods_name}, '%') or #{p1.goods_name} is null or #{p1.goods_name} = '' )"
                    + "     AND (t8.name like concat('%', #{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')"
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"

                    + "    <if test='p1.query_type == 1'>                                                              "
                    + "      and ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0               "
                    + "      and t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + " '                        "
                    + "    </if>                                                                                       "

                    + "    <if test='p1.query_type == 2'>                                                             "
                    + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "    </if>                                                                                      "
                    + "   ${p1.params.dataScopeAnnotation}  "

                    + "    	GROUP BY t3.id                                                                            "
                    + " </script>"
    })
    IPage<BContractReportVo> queryQtyLossList(@Param("p1") BContractReportVo param, Page<BMonitorEntity> page);

    /**
     * 损耗报表求和
     * @param param COALESCE
     * @return
     */
    @Select({
            " <script>                                                                                                 "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + "    SELECT                                                                                      "
                    + "    <if test='p1.query_type == 1'>                                                              "
                    + "    	sum(case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
                    + "     else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty )-ifnull(t9.qty,0), 0 ) end ) AS qty         "
                    + "    </if>                                                                                       "

                    + "    <if test='p1.query_type == 2'>                                                              "
                    + "    	sum(ifnull( t6.qty, t7.qty)) AS qty                                                        "
                    + "    </if>                                                                                       "

                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                             "
                    + "    	LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                                "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "     LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                       "
                    + "     LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "    	WHERE true                                                                                 "
                    + "     AND (t3.name LIKE CONCAT('%', #{p1.goods_name}, '%') or #{p1.goods_name} is null or #{p1.goods_name} = '' )"
                    + "     AND (t8.name like concat('%', #{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')"
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"

                    + "    <if test='p1.query_type == 1'>                                                              "
                    + "      and t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + " '                        "
                    + "      and ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0               "
                    + "    </if>                                                                                       "

                    + "    <if test='p1.query_type == 2'>                                                              "
                    + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "    </if>                                                                                       "
                    + "    ${p1.params.dataScopeAnnotation}  "
                    + " </script>"
    })
    BContractReportVo queryQtyLossListSum(@Param("p1") BContractReportVo param);

    /**
     * 损耗报表全部导出
     * @param param
     * @return
     */
    @Select({
            " <script>                                                                                                 "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + "    SELECT                                                                                      "
                    + "    	sum(case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
                    + "     else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty )-ifnull(t9.qty,0), 0 ) end ) AS qty,       "
                    + "    	t3.NAME AS goods_name,                                                                     "
                    + "     @row_num:= @row_num+ 1 as no                                                               "
                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                             "
                    + "    	LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                                "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "     LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                       "
                    + "     LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "  ,(select @row_num:=0) t8                                                                      "
                    + "    	WHERE t.status =  " +  DictConstant.DICT_B_MONITOR_STATUS_SEVEN
                    + "     AND (t3.name LIKE CONCAT('%', #{p1.goods_name}, '%') or #{p1.goods_name} is null or #{p1.goods_name} = '' )"
                    + "     AND (t8.name like concat('%', #{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')"
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "     AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0                "
                    + "    ${p1.params.dataScopeAnnotation}  "
                    + "    	GROUP BY t3.id                                                                             "
                    + " </script>"
    })
    List<BQtyLossReportExportVo> queryQtyLossListExportAll(@Param("p1") BContractReportVo param);

    /**
     * 损耗报表， 部分导出
     * @param param
     * @return
     */
    @Select({
            " <script>                                                                                                "
                    + "    SELECT                                                                                     "
                    + "    	sum(case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
                    + "     else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty )-ifnull(t9.qty,0), 0 ) end ) AS qty,       "
                    + "    	t3.NAME AS goods_name,                                                                    "
                    + "     @row_num:= @row_num+ 1 as no                                                              "
                    + "    FROM                                                                                       "
                    + "    	b_monitor t                                                                               "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                          "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                            "
                    + "    	LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                               "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                     "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                        "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                   "
                    + "     LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "     ,(select @row_num:=0) t8                                                                  "
                    + "    	WHERE t.status =  " +  DictConstant.DICT_B_MONITOR_STATUS_SEVEN
                    + "     AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0                "
                    + "    <if test='p1 != null and p1.size != 0 '>                                                   "
                    + "       and t3.id in                                                                            "
                    + "       <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>    "
                    + "         #{item.id_num,jdbcType=INTEGER}                                                           "
                    + "        </foreach>                                                                             "
                    + "    </if>"
                    + "    	GROUP BY t3.id                                                                            "
                    + " </script>"
    })
    List<BQtyLossReportExportVo> queryQtyLossListExport(@Param("p1") List<BContractReportVo> param);

    /**
     * 物流订单损耗明细
     * @param searchCondition
     * @param pageCondition
     * @return
     */
    @Select({ " <script> "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
            + "    SELECT                                                                                      "
            + "    	t8.label status_name,                                                                      "
            + "    	t1.CODE AS schedule_code,                                                                  "
            + "    	sum(case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
            + "     else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty )-ifnull(t13.qty,0), 0 ) end ) AS qty_loss,   "
            + "     sum(ifnull( t6.qty, t7.qty )) - sum(ifnull(t13.qty,0)) out_qty,                                                     "
            + "    	t3.spec ,                                                                                  "
            + "     t3.name sku_name,                                                                          "
            + "     t.code code,                                                                               "
            + "    	t3.pm AS pm,                                                                               "
            + "     t3.code sku_code,                                                                          "
            + "     concat(ifnull(t1.code, ''), '_', ifnull(t2.id, ''), '_', ifnull(t3.id, '')) id_str,        "
            + "     t1.monitor_count counts,                                                                   "
            + "     t1.c_time,                                                                                 "
            + "     t1.u_time,                                                                                 "
            + "    	t2.NAME AS customer_name,                                                                  "
            + "    	t11.NAME AS out_warehouse_name,                                                            "
            + "    	t12.NAME AS in_warehouse_name                                                              "
            + "    FROM                                                                                        "
            + "    	b_monitor t                                                                                "
            + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
            + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                           "
            + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                             "
            + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
            + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
            + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
            + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
            + "    	LEFT JOIN v_dict_info t8 ON  t1.status = t8.dict_value AND t8.CODE =  + '" + DictConstant.DICT_B_SCHEDULE_STATUS + "' "
            + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                "
//            + "  LEFT JOIN (select schedule_id,count(1) counts                                                 "
//            + "     from b_monitor where status != '"+ DictConstant.DICT_B_MONITOR_STATUS_EIGHT +"'            "
//            + " group by schedule_id) t10 ON t1.id = t10.schedule_id                                           "
            + "     LEFT JOIN m_warehouse t11 ON t1.out_warehouse_id = t11.id                                  "
            + "     LEFT JOIN m_warehouse t12 ON t1.in_warehouse_id = t12.id                                   "
            + "     LEFT JOIN b_return_relation t13 ON t13.serial_id = t.id AND t13.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
            + "     AND  t13.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
            + "    WHERE true                                                                                  "
            + "    	    and (t9.id = #{p1.id} or #{p1.id} is null)                                             "
            + "    	    and (t1.code like concat('%', #{p1.schedule_code}, '%') or #{p1.schedule_code} is null or #{p1.schedule_code} = '')"
            + "    	    and (t3.name like concat('%', #{p1.sku_name}, '%') or t9.name like concat('%', #{p1.sku_name}, '%') or  #{p1.sku_name} is null or  #{p1.sku_name} = '')"
            + "    	    and (t3.code like concat('%', #{p1.goods_code}, '%') or t9.code like concat('%', #{p1.goods_code}, '%') or #{p1.goods_code} is null or #{p1.goods_code} = '')"
            + "    	    and (t2.NAME like concat('%', #{p1.customer_name}, '%') or #{p1.customer_name} is null or #{p1.customer_name} = '') "
            + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
            + "     and (DATE_FORMAT(t1.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
            + "    <if test='p1.query_type == 1'>                                                              "
            + "      and t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + " '                        "
            + "     AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0                "
            + "    </if>                                                                                       "

            + "    <if test='p1.query_type == 2'>                                                              "
            + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
            + "    </if>                                                                                       "
            + "    ${p1.params.dataScopeAnnotation}  "
            + "         group by t1.code, t2.id, t3.id                                                         "

            + " </script> "
    })
    IPage<BQtyLossScheduleReportVo> queryScheduleList(@Param("p1") BQtyLossScheduleReportVo searchCondition, Page<BQtyLossScheduleReportVo> pageCondition);

    /**
     * 物流订单损耗明细
     * @param param
     * @return
     */
    @Select({ " <script> "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
            + " select sum(qty_loss) qty_loss from (                                                           "
            + "    SELECT                                                                                      "
            + "    <if test='p1.query_type == 1'>                                                              "
            + "    	sum(case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
            + "     else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty )-ifnull(t13.qty,0), 0 ) end ) AS qty_loss    "
            + "    </if>                                                                                       "

            + "    <if test='p1.query_type == 2'>                                                              "
            + "    	sum(ifnull( t6.qty, t7.qty)) -sum(ifnull(t13.qty,0)) AS qty_loss                                                   "
            + "    </if>                                                                                       "

            + "    FROM                                                                                        "
            + "    	b_monitor t                                                                                "
            + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
            + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                           "
            + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                             "
            + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
            + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
            + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
            + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
            + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                "
            + "    	LEFT JOIN v_dict_info t8 ON  t1.status = t8.dict_value AND t8.CODE =  + '" + DictConstant.DICT_B_SCHEDULE_STATUS + "' "
            + "     LEFT JOIN b_return_relation t13 ON t13.serial_id = t.id AND t13.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
            + "     AND  t13.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
            + "     where true                                                                                 "
            + "    	    and (t9.id = #{p1.id} or #{p1.id} is null)                                             "
            + "    	    and (t1.code like concat('%', #{p1.schedule_code}, '%') or #{p1.schedule_code} is null or #{p1.schedule_code} = '')"
            + "    	    and (t3.name like concat('%', #{p1.sku_name}, '%') or t9.name like concat('%', #{p1.sku_name}, '%') or  #{p1.sku_name} is null or  #{p1.sku_name} = '')"
            + "    	    and (t3.code like concat('%', #{p1.goods_code}, '%') or t9.code like concat('%', #{p1.goods_code}, '%') or #{p1.goods_code} is null or #{p1.goods_code} = '')"
            + "    	    and (t2.NAME like concat('%', #{p1.customer_name}, '%') or #{p1.customer_name} is null or #{p1.customer_name} = '') "
            + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
            + "     and (DATE_FORMAT(t1.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
            + "    <if test='p1.query_type == 1'>                                                             "
            + "      and t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + " '                       "
            + "     AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0               "
            + "    </if>                                                                                      "

            + "    <if test='p1.query_type == 2'>                                                             "
            + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
            + "    </if>                                                                                      "
            + "    ${p1.params.dataScopeAnnotation}  "
            + "     group by t1.code, t2.id, t3.id "

            + "  ) tt1                                                       "
            + " </script> "
    })
    BQtyLossScheduleReportVo queryScheduleListSum(@Param("p1") BQtyLossScheduleReportVo param);

    /**
     * 全部导出
     * @param param
     * @return
     */
    @Select({
            " <script> "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + "    SELECT                                                                                      "
                    + "    	t8.label status_name,                                                                      "
                    + "    	t1.CODE AS schedule_code,                                                                  "
                    + "    	sum(case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
                    + "     else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty )-ifnull(t13.qty,0), 0 ) end ) AS qty_loss,   "
                    + "    	t3.spec ,                                                                                  "
                    + "     t3.name goods_name,                                                                        "
                    + "     @row_num:= @row_num+ 1 as no,                                                              "
                    + "    	t3.pm AS pm,                                                                               "
                    + "    	t1.monitor_count as counts ,                                                               "
                    + "    	t2.NAME AS customer_name                                                                   "
                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                           "
                    + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                             "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "    	LEFT JOIN v_dict_info t8 ON  t1.status = t8.dict_value AND t8.CODE =  + '" + DictConstant.DICT_B_SCHEDULE_STATUS + "' "
                    + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                "
//                    + "  LEFT JOIN (select schedule_id,count(1) counts                                                 "
//                    + "     from b_monitor where status != '"+ DictConstant.DICT_B_MONITOR_STATUS_EIGHT +"'            "
//                    + " group by schedule_id) t11 ON t1.id = t11.schedule_id                                           "
                    + "     LEFT JOIN b_return_relation t13 ON t13.serial_id = t.id AND t13.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t13.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "     ,(select @row_num:=0) t10                                                                  "
                    + "    WHERE t.status = '" +  DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "'                        "
                    + "    	    and (t9.id = #{p1.id} or #{p1.id} is null)                                             "
                    + "    	    and (t1.code like concat('%', #{p1.schedule_code}, '%') or #{p1.schedule_code} is null or #{p1.schedule_code} = '')"
                    + "    	    and (t3.name like concat('%', #{p1.sku_name}, '%') or t9.name like concat('%', #{p1.sku_name}, '%') or  #{p1.sku_name} is null or  #{p1.sku_name} = '')"
                    + "    	    and (t3.code like concat('%', #{p1.goods_code}, '%') or t9.code like concat('%', #{p1.goods_code}, '%') or #{p1.goods_code} is null or #{p1.goods_code} = '')"
                    + "    	    and (t2.NAME like concat('%', #{p1.customer_name}, '%') or #{p1.customer_name} is null or #{p1.customer_name} = '') "
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "     and (DATE_FORMAT(t1.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "    <if test='p1.query_type == 1'>                                                             "
                    + "     AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0                "
                    + "    </if>                                                                                      "
                    + "    ${p1.params.dataScopeAnnotation}  "
                    + "     group by t1.code, t2.id, t3.id                                                             "
                    + " </script>                                                                                      "
    })
    List<BQtyLossScheduleDetailExportVo> queryScheduleListExportAll(@Param("p1") BQtyLossScheduleReportVo param);

    /**
     * 全部导出
     * @param param
     * @return
     */
    @Select({
            " <script> "
                    + "    SELECT                                                                                      "
                    + "    	t8.label status_name,                                                                      "
                    + "    	t1.CODE AS schedule_code,                                                                  "
                    + "    	sum(case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
                    + "     else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty )-ifnull(t13.qty,0), 0 ) end ) AS qty_loss,   "
                    + "    	t3.spec ,                                                                                  "
                    + "     t3.name goods_name,                                                                        "
                    + "     @row_num:= @row_num+ 1 as no,                                                              "
                    + "    	t3.pm AS pm,                                                                               "
                    + "    	t11.counts,                                                                                "
                    + "    	t2.NAME AS customer_name                                                                   "
                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                           "
                    + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                             "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "    	LEFT JOIN v_dict_info t8 ON  t1.status = t8.dict_value AND t8.CODE =  + '" + DictConstant.DICT_B_SCHEDULE_STATUS + "' "
                    + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                "
                    + "  LEFT JOIN (select schedule_id,count(1) counts                                                 "
                    + "     from b_monitor where status != '"+ DictConstant.DICT_B_MONITOR_STATUS_EIGHT +"'            "
                    + " group by schedule_id) t11 ON t1.id = t11.schedule_id                                           "
                    + "     LEFT JOIN b_return_relation t13 ON t13.serial_id = t.id AND t13.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t13.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "     ,(select @row_num:=0) t10                                                                  "
                    + "    WHERE t.status = " +  DictConstant.DICT_B_MONITOR_STATUS_SEVEN
                    + "          AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0           "
                    + "    	<if test='p1 != null and p1.size != 0'>                                                    "
                    + "        and concat(ifnull(t1.code, ''), '_', ifnull(t2.id, ''), '_', ifnull(t3.id, '')) in      "
                    + "        <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>    "
                    + "             #{item.id_str}                                                                     "
                    + "        </foreach>                                                                              "
                    + "    	</if>                                                                                      "
                    + "     group by t1.code, t2.id, t3.id                                                             "
                    + " </script>                                                                                      "
    })
    List<BQtyLossScheduleDetailExportVo> queryScheduleListExport(@Param("p1") List<BQtyLossScheduleReportVo> param);

    /**
     * 监管任务损耗明细
     * @param searchCondition
     * @param pageCondition
     * @return
     */
    @Select({
            " <script> "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + "    SELECT                                                                                      "
                    + "    	t8.label status_name,                                                                      "
                    + "    	t1.CODE AS schedule_code,                                                                  "
                    + "     case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
                    + "    	else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ) - ifnull(t13.qty,0), 0 ) end AS qty_loss,     "
                    + "     ifnull(t4.qty,t5.qty) as in_qty,                                                           "
                    + "     ifnull(t6.qty,t7.qty) as out_qty,                                                          "
                    + "     ifnull(t6.qty,t7.qty) - ifnull(t13.qty,0) as out_way_qty,                                                          "
                    + "    	t3.spec ,                                                                                  "
                    + "    	t3.pm ,                                                                                    "
                    + "     t.code code,                                                                               "
                    + "     t.id,                                                                                      "
                    + "     t10.no vehicle_no,                                                                         "
                    + "     t3.name sku_name,                                                                          "
                    + "    	t2.NAME AS customer_name,                                                                  "
                    + "    	t11.NAME AS out_warehouse_name,                                                            "
                    + "    	t12.NAME AS in_warehouse_name                                                              "
                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                           "
                    + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                             "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "    	LEFT JOIN v_dict_info t8 ON t8.CODE = '"+ DictConstant.DICT_B_MONITOR_STATUS +"' AND t.status = t8.dict_value"
                    + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                "
                    + "     LEFT JOIN m_vehicle t10 ON t.vehicle_id = t10.id                                              "
                    + "     LEFT JOIN m_warehouse t11 ON t1.out_warehouse_id = t11.id                                  "
                    + "     LEFT JOIN m_warehouse t12 ON t1.in_warehouse_id = t12.id                                   "
                    + "     LEFT JOIN b_return_relation t13 ON t13.serial_id = t.id AND t13.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t13.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "    WHERE true                                                                                  "
                    + "      and (t9.id = #{p1.id} or #{p1.id} is null)                                                "
                    + "   ${p1.params.dataScopeAnnotation}                                                             "
                    + "      and (t1.code like concat('%', #{p1.schedule_code}, '%') or #{p1.schedule_code} is null or #{p1.schedule_code} = '')"
                    + "      and (t.code like concat('%', #{p1.code}, '%') or #{p1.code} is null or #{p1.code} = '')   "
                    + "      and (t3.name like concat('%', #{p1.sku_name}, '%') or #{p1.sku_name} is null or #{p1.sku_name} = '')"
                    + "      and (t3.code like concat('%', #{p1.sku_code}, '%') or #{p1.sku_code} is null or #{p1.sku_code} = '')"
                    + "      and (t2.name like concat('%', #{p1.customer_name}, '%') or #{p1.customer_name} is null or #{p1.customer_name} = '')"
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "    <if test='p1.query_type == 1'>                                                              "
                    + "      and t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "'                         "
                    + "      AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0                "
                    + "    </if>                                                                                       "

                    + "    <if test='p1.query_type == 2'>                                                              "
                    + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "    </if>                                                                                       "
                    + " </script> "
    })
    IPage<BQtyLossScheduleReportVo> queryMonitorList(@Param("p1") BQtyLossScheduleReportVo searchCondition, Page<BMonitorEntity> pageCondition);

    /**
     * 监管任务详情 求和
     * @param param
     * @return
     */
    @Select({
            " <script> "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + "    SELECT                                                                                                                           "
                    + "    	sum(case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0                                 "
                    + "     else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ) - ifnull(t13.qty,0), 0 ) end ) AS qty_loss,                                        "
                    + "     sum(ifnull(t4.qty,t5.qty)) as in_qty,                                                                                           "
                    + "     sum(ifnull(t6.qty,t7.qty)) as out_qty,                                                                                           "
                    + "     sum(ifnull(t6.qty,t7.qty)) -sum(ifnull(t13.qty,0)) as out_sum_way_qty                                                                                           "
                    + "    FROM                                                                                                                             "
                    + "    	b_monitor t                                                                                                                     "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                                                                "
                    + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                                                                "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                                                               "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                                                           "
                    + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                                                                  "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                                                              "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                                                         "
                    + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                                                     "
                    + "     LEFT JOIN b_return_relation t13 ON t13.serial_id = t.id AND t13.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t13.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "    WHERE true                                                                                                                       "
                    + "      and (t9.id = #{p1.id} or #{p1.id} is null)                                                                                     "
                    + "   ${p1.params.dataScopeAnnotation}                                                                                                  "
                    + "      and (t1.code like concat('%', #{p1.schedule_code}, '%') or #{p1.schedule_code} is null or #{p1.schedule_code} = '')            "
                    + "      and (t.code like concat('%', #{p1.code}, '%') or #{p1.code} is null or #{p1.code} = '')                                        "
                    + "      and (t3.name like concat('%', #{p1.sku_name}, '%') or #{p1.sku_name} is null or #{p1.sku_name} = '')                           "
                    + "      and (t3.code like concat('%', #{p1.sku_code}, '%') or #{p1.sku_code} is null or #{p1.sku_code} = '')                           "
                    + "      and (t2.name like concat('%', #{p1.customer_name}, '%') or #{p1.customer_name} is null or #{p1.customer_name} = '')            "
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                           "

                    + "    <if test='p1.query_type == 1'>                                                              "
                    + "      and t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "'                         "
                    + "    	 and ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ) &gt; 0                           "
                    + "    </if>                                                                                       "

                    + "    <if test='p1.query_type == 2'>                                                              "
                    + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "    </if>                                                                                      "

                    + " </script>                                                                                       "
    })
    BQtyLossScheduleReportVo queryMonitorListSum(@Param("p1") BQtyLossScheduleReportVo param);

    @Select({
            " <script> "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + "    SELECT                                                                                      "
                    + "     @row_num:= @row_num+ 1 as no,                                                              "
                    + "    	t8.label status_name,                                                                      "
                    + "    	t1.CODE AS schedule_code,                                                                  "
                    + "     case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
                    + "    	ELSE ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty )-ifnull(t13.qty,0), 0 ) end AS qty_loss,     "
                    + "     ifnull(t4.qty,t5.qty) as in_qty,                                                           "
                    + "     ifnull(t6.qty,t7.qty) as out_qty,                                                          "
                    + "     ifnull(t6.qty,t7.qty) - ifnull(t13.qty,0) as out_way_qty,                                                          "
                    + "    	t3.spec ,                                                                                  "
                    + "    	t3.pm ,                                                                                    "
                    + "    	t3.name sku_name,                                                                               "
                    + "     t.code code,                                                                               "
                    + "     t.id,                                                                                      "
                    + "     t10.no vehicle_no,                                                                           "
                    + "    	t2.NAME AS customer_name                                                                   "
                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                           "
                    + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                             "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "    	LEFT JOIN v_dict_info t8 ON t8.CODE = '"+ DictConstant.DICT_B_MONITOR_STATUS +"' AND t.status = t8.dict_value"
                    + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                "
                    + "     LEFT JOIN m_vehicle t10 ON t.vehicle_id = t10.id                                           "
                    + "     LEFT JOIN b_return_relation t13 ON t13.serial_id = t.id AND t13.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t13.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "   ,(select @row_num:=0) t11                                                                    "
                    + "    WHERE t.status = '" +  DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "'                        "
                    + "   ${p1.params.dataScopeAnnotation}                                                             "
                    + "      and (t9.id = #{p1.id} or #{p1.id} is null)                                                "
                    + "      and (t1.code like concat('%', #{p1.schedule_code}, '%') or #{p1.schedule_code} is null or #{p1.schedule_code} = '')"
                    + "      and (t.code like concat('%', #{p1.code}, '%') or #{p1.code} is null or #{p1.code} = '')   "
                    + "      and (t3.name like concat('%', #{p1.sku_name}, '%') or #{p1.sku_name} is null or #{p1.sku_name} = '')"
                    + "      and (t3.code like concat('%', #{p1.sku_code}, '%') or #{p1.sku_code} is null or #{p1.sku_code} = '')"
                    + "      and (t2.name like concat('%', #{p1.customer_name}, '%') or #{p1.customer_name} is null or #{p1.customer_name} = '')"
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "    	 and ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ) &gt; 0                            "
                    + " </script> "
    })
    List<BQtyLossMonitorDetailExportVo> queryMonitorListExportAll(@Param("p1") BQtyLossScheduleReportVo param);

    /**
     * 监管任务详情导出 部分
     * @param param
     * @return
     */
    @Select({
            " <script> "
                    + "    SELECT                                                                                      "
                    + "    	t8.label status_name,                                                                      "
                    + "     @row_num:= @row_num+ 1 as no,                                                              "
                    + "    	t1.CODE AS schedule_code,                                                                  "
                    + "     case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
                    + "    	else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty )-ifnull(t13.qty,0), 0 ) end AS qty_loss,     "
                    + "     ifnull(t4.qty,t5.qty) as in_qty,                                                           "
                    + "     ifnull(t6.qty,t7.qty) as out_qty,                                                          "
                    + "     ifnull(t6.qty,t7.qty) - ifnull(t13.qty,0) as out_way_qty,                                                          "
                    + "    	t3.spec ,                                                                                  "
                    + "    	t3.pm,                                                                                     "
                    + "    	t3.name sku_name,                                                                          "
                    + "     t.code code,                                                                               "
                    + "     t.id,                                                                                      "
                    + "     t10.no vehicle_no,                                                                         "
                    + "    	t2.NAME AS customer_name                                                                   "
                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                           "
                    + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                             "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "    	LEFT JOIN v_dict_info t8 ON t8.CODE = 'b_monitor_status' AND t.status = t8.dict_value"
                    + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                "
                    + "     LEFT JOIN m_vehicle t10 ON t.vehicle_id = t10.id                                           "
                    + "     LEFT JOIN b_return_relation t13 ON t13.serial_id = t.id AND t13.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t13.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "   ,(select @row_num:=0) t11                                                                    "
                    + "    WHERE t.status = '" +  DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "'                        "
                    + "    	 and ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ) &gt; 0                            "
                    + "    	<if test='p1 != null and p1.size != 0'>                                                    "
                    + "        and t.id in                                          "
                    + "        <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>    "
                    + "             #{item.id}                                                                         "
                    + "        </foreach>                                                                              "
                    + "    	</if>                                                                                      "
                    + " </script> "
    })
    List<BQtyLossMonitorDetailExportVo> queryMonitorListExport(@Param("p1") List<BQtyLossScheduleReportVo> param);

    /**
     * 在途报表， 全部导出
     * @param param
     * @return
     */
    @Select({
            " <script>                                                                                                "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + "    SELECT                                                                                     "
                    + "    	sum(ifnull( t6.qty, t7.qty )) AS qty,                                                      "
                    + "    	t3.NAME AS goods_name,                                                                    "
                    + "     @row_num:= @row_num+ 1 as no                                                              "
                    + "    FROM                                                                                       "
                    + "    	b_monitor t                                                                               "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                          "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                            "
                    + "    	LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                               "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                        "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                   "
                    + "     LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                      "
                    + "     ,(select @row_num:=0) t9                                                                  "
                    + "    	WHERE true                                                                                "
                    + "     and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "     and (t3.name LIKE CONCAT('%', #{p1.goods_name}, '%') or #{p1.goods_name} is null or #{p1.goods_name} = '')"
                    + "     AND (t8.name like concat('%', #{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')"
                    + "   ${p1.params.dataScopeAnnotation}                                                             "
                    + "    	GROUP BY t3.id                                                                            "
                    + " </script>"
    })
    List<BInTransitReportExportVo> queryOnWayListExportAll(@Param("p1") BContractReportVo param);

    /**
     * 在途报表 部分导出
     * @param param
     * @return
     */
    @Select({
            " <script>                                                                                                "
                    + "    SELECT                                                                                     "
                    + "    	sum(ifnull( t6.qty, t7.qty )) AS qty,                                                     "
                    + "    	t3.NAME AS goods_name,                                                                    "
                    + "     @row_num:= @row_num+ 1 as no                                                              "
                    + "    FROM                                                                                       "
                    + "    	b_monitor t                                                                               "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                          "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                            "
                    + "    	LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                               "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                     "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                        "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                   "
                    + "     ,(select @row_num:=0) t8                                                                  "
                    + "    	WHERE true                                                                                "
                    + "    <if test='p1 != null and p1.size != 0 '>                                                   "
                    + "       and t3.id in                                                                            "
                    + "       <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>    "
                    + "         #{item.id_num,jdbcType=INTEGER}                                                           "
                    + "        </foreach>                                                                             "
                    + "    </if>"
                    + "    	GROUP BY t3.id                                                                            "
                    + " </script>"
    })
    List<BInTransitReportExportVo> queryOnWayListExport(@Param("p1") List<BContractReportVo> param);

    /**
     * 物流订单 在途明细 全部导出
     * @param param
     * @return
     */
    @Select({
            " <script> "
                    + " ${p1.params.dataScopeAnnotation_with}                                                          "
                    + " select                                                                                         "
                    + "   tab1.status_name,                                                                            "
                    + "   tab1.schedule_code,                                                                          "
                    + "   tab1.qty_loss,                                                                               "
                    + "   tab1.spec,                                                                                   "
                    + "   tab1.goods_name,                                                                             "
                    + "   tab1.pm,                                                                                     "
                    + "   tab1.counts,                                                                                 "
                    + "   tab1.customer_name,                                                                          "
                    + "   @row_num:= @row_num+ 1 as no,                                                                "
                    + "   tab1.counts,                                                                                 "
                    + "   tab1.out_warehouse_name,                                                                     "
                    + "   tab1.in_warehouse_name,                                                                      "
                    + "   tab1.c_time,                                                                                 "
                    + "   tab1.u_time                                                                                 "
                    + " from (                                                                                         "
                    + "    SELECT                                                                                      "
                    + "    	t8.label status_name,                                                                      "
                    + "    	t1.CODE AS schedule_code,                                                                  "
                    + "    	sum(ifnull( t6.qty, t7.qty )) - sum(ifnull(t14.qty,0)) AS qty_loss,                   "
                    + "    	t3.spec ,                                                                                  "
                    + "     t3.name goods_name,                                                                        "
                    + "    	t3.pm AS pm,                                                                               "
                    + "    	t11.counts,                                                                                "
                    + "    	t2.NAME AS customer_name,                                                                  "
                    + "    	t13.NAME AS out_warehouse_name,                                                            "
                    + "    	t12.NAME AS in_warehouse_name,                                                             "
                    + "    	t1.c_time,                                                                                 "
                    + "    	t1.u_time                                                                                  "
                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                           "
                    + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                             "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "    	LEFT JOIN v_dict_info t8 ON  t1.status = t8.dict_value AND t8.CODE =  + '" + DictConstant.DICT_B_SCHEDULE_STATUS + "' "
                    + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                "
                    + "  LEFT JOIN (select schedule_id,count(1) counts                                                 "
                    + "     from b_monitor where status != '"+ DictConstant.DICT_B_MONITOR_STATUS_EIGHT +"'            "
                    + " group by schedule_id) t11 ON t1.id = t11.schedule_id                                           "
                    + "     LEFT JOIN m_warehouse t12 ON t1.in_warehouse_id = t12.id                                   "
                    + "     LEFT JOIN m_warehouse t13 ON t1.out_warehouse_id = t13.id                                  "
                    + "     LEFT JOIN b_return_relation t14 ON t14.serial_id = t.id AND t14.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t14.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "    WHERE true                                                                                  "
                    + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "    	    and (t9.id = #{p1.id} or #{p1.id} is null)                                             "
                    + "    	    and (t1.code like concat('%', #{p1.schedule_code}, '%') or #{p1.schedule_code} is null or #{p1.schedule_code} = '')"
                    + "    	    and (t3.name like concat('%', #{p1.sku_name}, '%') or t9.name like concat('%', #{p1.sku_name}, '%') or  #{p1.sku_name} is null or  #{p1.sku_name} = '')"
                    + "    	    and (t3.code like concat('%', #{p1.goods_code}, '%') or t9.code like concat('%', #{p1.goods_code}, '%') or #{p1.goods_code} is null or #{p1.goods_code} = '')"
                    + "    	    and (t2.NAME like concat('%', #{p1.customer_name}, '%') or #{p1.customer_name} is null or #{p1.customer_name} = '') "
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "     and (DATE_FORMAT(t1.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "   ${p1.params.dataScopeAnnotation}                                                             "
                    + "     group by t1.code, t2.id, t3.id) tab1                                                       "
                    + "     ,(select @row_num:=0) t10                                                                  "
                    + " </script>                                                                                      "
    })
    List<BScheduleLossInTransitExportVo> queryScheduleListWayExportAll(@Param("p1") BQtyLossScheduleReportVo param);

    /**
     * 物流在途明细，部分导出
     * @param param
     * @return
     */
    @Select({
            " <script> "
                    + " SELECT                                                                                         "
                    +  "  tab1.status_name,                                                                            "
                    +  "  tab1.schedule_code,                                                                          "
                    +  "  tab1.qty_loss,                                                                               "
                    +  "  tab1.spec,                                                                                   "
                    +  "  tab1.goods_name,                                                                             "
                    +  "  tab1.pm,                                                                                     "
                    +  "  tab1.counts,                                                                                 "
                    +  "  tab1.customer_name,                                                                          "
                    +  "  tab1.out_warehouse_name,                                                                     "
                    +  "  tab1.in_warehouse_name,                                                                      "
                    +  "  tab1.c_time,                                                                                 "
                    +  "  tab1.u_time,                                                                                 "
                    +  "  @row_num := @row_num + 1 AS NO                                                               "
                    + "  from (                                                                                        "
                    + "    SELECT                                                                                      "
                    + "    	t8.label status_name,                                                                      "
                    + "    	t1.CODE AS schedule_code,                                                                  "
                    + "    	sum(ifnull( t6.qty, t7.qty )) - sum(ifnull(t14.qty,0)) AS qty_loss,                                                     "
                    + "    	t3.spec ,                                                                                  "
                    + "     t3.name goods_name,                                                                        "
                    + "    	t3.pm AS pm,                                                                               "
                    + "    	t11.counts,                                                                                "
                    + "    	t2.NAME AS customer_name,                                                                  "
                    + "    	t13.NAME AS out_warehouse_name,                                                            "
                    + "    	t12.NAME AS in_warehouse_name,                                                             "
                    + "    	t1.c_time,                                                                                 "
                    + "    	t1.u_time                                                                                  "
                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                           "
                    + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                             "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "    	LEFT JOIN v_dict_info t8 ON  t1.status = t8.dict_value AND t8.CODE =  + '" + DictConstant.DICT_B_SCHEDULE_STATUS + "' "
                    + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                "
                    + "  LEFT JOIN (select schedule_id,count(1) counts                                                 "
                    + "     from b_monitor where status != '"+ DictConstant.DICT_B_MONITOR_STATUS_EIGHT +"'            "
                    + " group by schedule_id) t11 ON t1.id = t11.schedule_id                                           "
                    + "     LEFT JOIN m_warehouse t12 ON t1.in_warehouse_id = t12.id                                   "
                    + "     LEFT JOIN m_warehouse t13 ON t1.out_warehouse_id = t13.id                                  "
                    + "     LEFT JOIN b_return_relation t14 ON t14.serial_id = t.id AND t14.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t14.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "    WHERE true                                                                                  "
                    + "    	<if test='p1 != null and p1.size != 0'>                                                    "
                    + "        and concat(ifnull(t1.code, ''), '_', ifnull(t2.id, ''), '_', ifnull(t3.id, '')) in                                          "
                    + "        <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>"
                    + "             #{item.id_str}                                                                     "
                    + "        </foreach>                                                                              "
                    + "    	</if>                                                                                      "
                    + "      group by t1.CODE, t2.id, t3.id                                                            "
                    + " ) tab1 ,(select @row_num:=0) t10                                                               "
                    + " </script>                                                                                      "
    })
    List<BScheduleLossInTransitExportVo> queryScheduleListWayExport(@Param("p1") List<BQtyLossScheduleReportVo> param);

    /**
     * 损耗 在途 汇总 求和
     * @param param
     * @return
     */
    @Select({
            " <script>                                                                                                 "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + "  select sum(qty) qty from (                                                                    "
                    + "    SELECT                                                                                      "

                    + "    <if test='p1.query_type == 1'>                                                              "
                    + "    	sum(case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
                    + "     else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ) - ifnull(t9.qty,0), 0 ) end ) AS qty         "
                    + "    </if>                                                                                       "

                    + "    <if test='p1.query_type == 2'>                                                              "
                    + "    	sum(ifnull( t6.qty, t7.qty)) AS qty                                                        "
                    + "    </if>                                                                                       "
                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                             "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "     LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                       "
                    + "     LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "    	WHERE true                                                                                 "
                    + "     AND (t8.name like concat('%', #{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')"
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "    <if test='p1.query_type == 1'>                                                              "
                    + "      and t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + " '                        "
                    + "     AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0                "
                    + "    </if>                                                                                       "
                    + "   ${p1.params.dataScopeAnnotation}                                                             "

                    + "    <if test='p1.query_type == 2'>                                                              "
                    + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "    </if>                                                                                       "
                    + "    	GROUP BY t8.id                                                                             "
                    + " ) tt1                                                                                          "
                    + " </script>"
    })
    BContractReportVo queryQtyTotalSumList(@Param("p1") BContractReportVo param);

    /**
     * 监管任务在途明细 导出
     * @param param
     * @return
     */
    @Select({
            " <script> "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + "    SELECT                                                                                      "
                    + "    	t8.label status_name,                                                                      "
                    + "     @row_num:= @row_num+ 1 as no,                                                              "
                    + "    	ifnull( t6.qty, t7.qty ) - ifnull(t13.qty,0)  AS qty_loss,                            "
                    + "     COALESCE(t4.qty,t5.qty, 0) as in_qty,                                                      "
                    + "     ifnull(t6.qty,t7.qty) as out_qty,                                                          "
                    + "     ifnull(t6.qty,t7.qty) - ifnull(t13.qty,0) as out_way_qty,                                                          "
                    + "    	t3.spec ,                                                                                  "
                    + "     t.code code,                                                                               "
                    + "     t.id,                                                                                      "
                    + "     t3.name sku_name,                                                                          "
                    + "     t10.no vehicle_no,                                                                         "
                    + "    	t2.NAME AS customer_name,                                                                  "
                    + "    	t11.NAME AS out_warehouse_name,                                                            "
                    + "    	t12.NAME AS in_warehouse_name                                                              "
                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                           "
                    + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                             "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "    	LEFT JOIN v_dict_info t8 ON t8.CODE = 'b_monitor_status' AND t.status = t8.dict_value"
                    + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                "
                    + "     LEFT JOIN m_vehicle t10 ON t.vehicle_id = t10.id                                           "
                    + "     LEFT JOIN m_warehouse t11 ON t1.out_warehouse_id = t11.id                                  "
                    + "     LEFT JOIN m_warehouse t12 ON t1.in_warehouse_id = t12.id                                   "
                    + "     LEFT JOIN b_return_relation t13 ON t13.serial_id = t.id AND t13.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t13.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + " ,(select @row_num:=0) t23                                                                      "
                    + "    WHERE true                                                                                  "
                    + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "      and (t9.id = #{p1.id} or #{p1.id} is null)                                                "
                    + "      and (t1.code like concat('%', #{p1.schedule_code}, '%') or #{p1.schedule_code} is null or #{p1.schedule_code} = '')"
                    + "      and (t.code like concat('%', #{p1.code}, '%') or #{p1.code} is null or #{p1.code} = '')   "
                    + "      and (t3.name like concat('%', #{p1.sku_name}, '%') or #{p1.sku_name} is null or #{p1.sku_name} = '')"
                    + "      and (t3.code like concat('%', #{p1.sku_code}, '%') or #{p1.sku_code} is null or #{p1.sku_code} = '')"
                    + "      and (t2.name like concat('%', #{p1.customer_name}, '%') or #{p1.customer_name} is null or #{p1.customer_name} = '')"
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "   ${p1.params.dataScopeAnnotation}                                                             "
                    + " </script> "
    })
    List<BMonitorLossInTransitExportVo> queryMonitorWayListExportAll(@Param("p1") BQtyLossScheduleReportVo param);

    /**
     * 导出
     * @param param
     * @return
     */
    @Select({
            " <script> "
                    + "    SELECT                                                                                      "
                    + "    	t8.label status_name,                                                                      "
                    + "     @row_num:= @row_num+ 1 as no,                                                              "
                    + "    	ifnull( t6.qty, t7.qty ) - ifnull(t13.qty,0)  AS qty_loss,                            "
                    + "     COALESCE(t4.qty,t5.qty, 0) as in_qty,                                                      "
                    + "     ifnull(t6.qty,t7.qty) as out_qty,                                                          "
                    + "     ifnull(t6.qty,t7.qty) - ifnull(t13.qty,0) as out_way_qty,                                                          "
                    + "    	t3.spec ,                                                                                  "
                    + "     t.code code,                                                                               "
                    + "     t.id,                                                                                      "
                    + "     t10.no vehicle_no,                                                                         "
                    + "     t3.name sku_name,                                                                          "
                    + "    	t2.NAME AS customer_name,                                                                  "
                    + "    	t11.NAME AS out_warehouse_name,                                                            "
                    + "    	t12.NAME AS in_warehouse_name                                                              "
                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                           "
                    + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                             "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "    	LEFT JOIN v_dict_info t8 ON t8.CODE = 'b_monitor_status' AND t.status = t8.dict_value"
                    + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                "
                    + "     LEFT JOIN m_vehicle t10 ON t.vehicle_id = t10.id                                           "
                    + "     LEFT JOIN m_warehouse t11 ON t1.out_warehouse_id = t11.id                                  "
                    + "     LEFT JOIN m_warehouse t12 ON t1.in_warehouse_id = t12.id                                   "
                    + "     LEFT JOIN b_return_relation t13 ON t13.serial_id = t.id AND t13.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t13.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + " ,(select @row_num:=0) t23                                                                      "
                    + "    WHERE true                                                                                  "
                    + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "    	<if test='p1 != null and p1.size != 0'>                                                    "
                    + "        and t.id in                                          "
                    + "        <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>"
                    + "             #{item.id}                                                                     "
                    + "        </foreach>                                                                              "
                    + "    	</if>                                                                                      "
                    + " </script> "
    })
    List<BMonitorLossInTransitExportVo> queryMonitorWayListExport(@Param("p1") List<BQtyLossScheduleReportVo> param);

    /**
     * 损耗 在途 汇总
     * @param param
     * @param page
     * @return
     */
    @Select({
            " <script>                                                                                                "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + "    SELECT                                                                                     "

                    + "    <if test='p1.query_type == 1'>                                                             "
                    + "    	sum(case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
                    + "     else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty )-ifnull(t9.qty,0), 0 ) end ) AS qty,       "
//                    + "    	sum(ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 )) AS qty,             "
                    + "    </if>                                                                                      "

                    + "    <if test='p1.query_type == 2'>                                                             "
                    + "    	sum(ifnull( t6.qty, t7.qty)) AS qty,                                                      "
                    + "    </if>                                                                                      "

                    + "    	t8.NAME AS goods_prop  ,                                                                  "
                    + "     t8.code id                                                                                "
                    + "    FROM                                                                                       "
                    + "    	b_monitor t                                                                               "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                          "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                            "
                    + "    	LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                               "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                     "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                        "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                   "
                    + "     LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                      "
                    + "     LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "    	WHERE true                                                                                "
                    + "     AND (t8.name like concat('%', #{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')"
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "    <if test='p1.query_type == 1'>                                                              "
                    + "      and t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + " '                        "
                    + "     AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0                "
                    + "    </if>                                                                                       "
                    + "   ${p1.params.dataScopeAnnotation}                                                             "

                    + "    <if test='p1.query_type == 2'>                                                             "
                    + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "    </if>                                                                                      "

                    + "    	GROUP BY t8.id                                                                            "
                    + " </script>"
    })
    IPage<BContractReportVo> queryQtyTotalList(@Param("p1") BContractReportVo param, Page<BMonitorEntity> page);

    /**
     * 损耗 报表汇总 全部导出
     * @param param
     * @return
     */
    @Select(
            " <script>                                                                                                 "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + "    SELECT                                                                                      "
                    + "    	sum(case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
                    + "     else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty )-ifnull(t9.qty,0), 0 ) end ) AS qty,       "
                    + "    	t8.NAME AS goods_prop ,                                                                    "
                    + "     @row_num:= @row_num+ 1 as no                                                               "
                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                             "
                    + "    	LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                                "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "     LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                       "
                    + "     LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "     ,(select @row_num:=0) t10                                                                   "
                    + "    	WHERE                                                                                      "
                    + "       t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + " '                           "
                    + "       and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "       and (t8.name like concat('%', #{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')"
                    + "     AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0                "
                    + "   ${p1.params.dataScopeAnnotation}                                                             "
                    + "    	GROUP BY t8.id                                                                             "
                    + " </script>"
    )
    List<BQtyLossExportVo> queryQtyLossAllExportAll(@Param("p1") BContractReportVo param);

    /**
     * 损耗报表导出 部分
     *
     * @param param
     * @return
     */
    @Select({
            " <script>                                                                                                "
                    + "    SELECT                                                                                     "
                    + "    	sum(case when ifnull(t4.type,t5.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0"
                    + "     else ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty )-ifnull(t9.qty,0), 0 ) end ) AS qty,       "
                    + "    	t8.NAME AS goods_prop ,                                                                   "
                    + "     @row_num:= @row_num+ 1 as no                                                              "
                    + "    FROM                                                                                       "
                    + "    	b_monitor t                                                                               "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                          "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                            "
                    + "    	LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                               "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                     "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                        "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                   "
                    + "     LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                      "
                    + "     LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + "     ,(select @row_num:=0) t10                                                                   "
                    + "    	WHERE t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + " '                        "
                    + "     AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0                "
                    + "    <if test='p1 != null and p1.size != 0'>                                                    "
                    +  "     AND t8.code in                                                                             "
                    +  "      <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>     "
                    +  "          #{item.id}                                                                           "
                    +  "      </foreach>                                                                               "
                    + "    </if>                                                                                       "
                    + "    	GROUP BY t8.id                                                                            "
                    + " </script>"

    })
    List<BQtyLossExportVo> queryQtyLossExport(@Param("p1") List<BContractReportVo> param);

    @Select({
            " <script>                                                                                                "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + "    SELECT                                                                                     "
                    + "    	sum(ifnull( t6.qty, t7.qty)) AS qty,                                                      "
                    + "    	t8.NAME AS goods_prop ,                                                                   "
                    + "     @row_num:= @row_num+ 1 as no                                                              "
                    + "    FROM                                                                                       "
                    + "    	b_monitor t                                                                               "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                          "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                            "
                    + "    	LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                               "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                     "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                        "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                   "
                    + "     LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                      "
                    + "     ,(select @row_num:=0) t9                                                                     "
                    + "    	WHERE true                                                                                "
                    + "     and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "     and (t8.name like concat('%', #{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')"
                    + "   ${p1.params.dataScopeAnnotation}                                                             "
                    + "    	GROUP BY t8.id                                                                            "
                    + " </script>"
    })
    List<BQtyInTransitExportVo> queryQtyOnWayAllExportAll(@Param("p1") BContractReportVo param);

    @Select({
            " <script>                                                                                                "
                    + "    SELECT                                                                                     "
                    + "    	sum(ifnull( t6.qty, t7.qty)) AS qty,                                                      "
                    + "    	t8.NAME AS goods_prop ,                                                                   "
                    + "     @row_num:= @row_num+ 1 as no                                                              "
                    + "    FROM                                                                                       "
                    + "    	b_monitor t                                                                               "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                          "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                            "
                    + "    	LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                               "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                     "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                        "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                   "
                    + "     LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                      "
                    + "     ,(select @row_num:=0) t9                                                                  "
                    + "    	WHERE true                                                                                "
                    + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "    <if test='p1 != null and p1.size != 0'>                                                    "
                    +  "     AND t8.code in                                                                             "
                    +  "      <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>     "
                    +  "          #{item.id}                                                                           "
                    +  "      </foreach>                                                                               "
                    + "    </if>                                                                                       "
                    + "    	GROUP BY t8.id                                                                            "
                    + " </script>"

    })
    List<BQtyInTransitExportVo> queryQtyOnWayExport(@Param("p1") List<BContractReportVo> param);

    /**
     * 当日调度统计
     * @param param
     * @return
     */
    @Select({
            " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    +" SELECT                                                                                                   "
                    + " 	sum(ifnull( t20.qty, t21.qty )) AS in_qty,                                                 "
                    + " 	sum(ifnull( t22.qty, t23.qty )) AS out_qty,                                                "
                    + "            sum( case when ifnull(t20.type,t21.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0 else                              "
                    + "  if(ifnull(t22.qty,t23.qty) <= ifnull(t20.qty,t21.qty), 0, ifnull(ifnull(t22.qty,t23.qty) - ifnull(t20.qty,t21.qty)-ifnull(t25.qty,0), 0)) end) as qty_loss,   "
                    + "      DATE_FORMAT(now(), '%Y-%m-%d') date,                                                      "
                    + "     count(t.id) num   "
                    + " FROM                                                                                           "
                    + " 	b_monitor t                                                                                "
                    + " 	LEFT JOIN b_monitor_in t20 ON t20.monitor_id = t.id                                        "
                    + " 	LEFT JOIN b_monitor_unload t21 ON t21.monitor_id = t.id                                    "
                    + " 	LEFT JOIN b_monitor_out t22 ON t22.monitor_id = t.id                                       "
                    + " 	LEFT JOIN b_monitor_delivery t23 ON t23.monitor_id = t.id                                  "
                    + " 	left join b_schedule t24 on t.schedule_id = t24.id                                         "
                    + "     LEFT JOIN b_return_relation t25 ON t25.serial_id = t.id AND t25.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t25.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + " WHERE t.STATUS IN ( 1, 2, 3, 4, 5, 6, 7 )                                                      "
                    + "    and DATE_FORMAT(t.out_time, '%Y%m%d' ) = DATE_FORMAT(now(), '%Y%m%d' )                      "
                    + " ${p1.params.dataScopeAnnotation}                                                               "
    })
    BQtyLossScheduleReportVo getScheduleStatistics(@Param("p1") BQtyLossScheduleReportVo param);

    /**
     * 当日损耗统计
     * @param param
     * @return
     */
    @Select({
            " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    +" SELECT                                                                                                   "
                    + "            sum( case when ifnull(t20.type,t21.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0 else                              "
                    + "  if(ifnull(t22.qty,t23.qty) <= ifnull(t20.qty,t21.qty), 0, ifnull(ifnull(t22.qty,t23.qty) - ifnull(t20.qty,t21.qty)-ifnull(t25.qty,0), 0)) end) as qty_loss       "
                    + " FROM                                                                                           "
                    + " 	b_monitor t                                                                                "
                    + " 	LEFT JOIN b_monitor_in t20 ON t20.monitor_id = t.id                                        "
                    + " 	LEFT JOIN b_monitor_unload t21 ON t21.monitor_id = t.id                                    "
                    + " 	LEFT JOIN b_monitor_out t22 ON t22.monitor_id = t.id                                       "
                    + " 	LEFT JOIN b_monitor_delivery t23 ON t23.monitor_id = t.id                                  "
                    + " 	left join b_schedule t24 on t.schedule_id = t24.id                                         "
                    + "     LEFT JOIN b_return_relation t25 ON t25.serial_id = t.id AND t25.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    + "     AND  t25.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
                    + " WHERE t.STATUS = '7'                                                                           "
                    + "    and DATE_FORMAT(t.in_time, '%Y%m%d' ) = DATE_FORMAT(now(), '%Y%m%d' )                       "
                    + " ${p1.params.dataScopeAnnotation}                                                               "
    })
    BigDecimal getScheduleLossStatistics(@Param("p1") BQtyLossScheduleReportVo param);

    /**
     * 损耗, 在途报表汇总
     * @param param
     * @return
     */
    @Select({
            " <script>                                                                                                "
                    + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
                    + " select count(1) from (                                                                        "
                    + "    SELECT                                                                                     "
                    + "     t8.code                                                                                   "
                    + "    FROM                                                                                       "
                    + "    	b_monitor t                                                                               "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                          "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                            "
                    + "    	LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                               "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                     "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                        "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                   "
                    + "     LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                      "
                    + "    	WHERE true                                                                                "
                    + "     AND (t8.name like concat('%', #{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')"
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "    <if test='p1.query_type == 1'>                                                              "
                    + "      and t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + " '                        "
                    + "     AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0                "
                    + "    </if>                                                                                       "
                    + "   ${p1.params.dataScopeAnnotation}                                                             "
                    + "    <if test='p1.query_type == 2'>                                                              "
                    + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "    </if>                                                                                       "
                    + "    	GROUP BY t8.id ) tt1                                                                       "
                    + " </script>"
    })
    int selectLossExportNum(@Param("p1") BContractReportVo param);

    /**
     * 损耗, 在途报表汇总
     * @param param
     * @return
     */
    @Select({
            " <script>                                                                                                "
                    + " ${p1.params.dataScopeAnnotation_with}                                                         "
                    + "    SELECT count(1) from (                                                                     "
                    + "      select t3.id                                                                             "
                    + "    FROM                                                                                       "
                    + "    	b_monitor t                                                                               "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                          "
                    + "    	LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                            "
                    + "    	LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                               "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                     "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                        "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                   "
                    + "     LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                      "
                    + "    	WHERE true                                                                                "
                    + "     AND (t3.name LIKE CONCAT('%', #{p1.goods_name}, '%') or #{p1.goods_name} is null or #{p1.goods_name} = '' )"
                    + "     AND (t8.name like concat('%', #{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')"
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "    <if test='p1.query_type == 1'>                                                              "
                    + "      and ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0               "
                    + "      and t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + " '                        "
                    + "    </if>                                                                                       "
                    + "    <if test='p1.query_type == 2'>                                                              "
                    + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "    </if>                                                                                       "
                    + "   ${p1.params.dataScopeAnnotation}                                                             "
                    + "    	GROUP BY t3.id ) tt1                                                                       "
                    + " </script>"
    })
    int selectLossDetailExportNum(@Param("p1") BContractReportVo param);

    /**
     * 物流订单损耗 在途明细
     * @param param
     * @return
     */
    @Select({ " <script> "
            + " ${p1.params.dataScopeAnnotation_with}                                                          "
            + "    SELECT count(1) from (                                                                      "
            + "    	  select t.id                                                                              "
            + "    FROM                                                                                        "
            + "    	b_monitor t                                                                                "
            + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
            + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                           "
            + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                             "
            + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
            + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
            + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
            + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
            + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                "
//            + "  LEFT JOIN (select schedule_id,count(1) counts                                                 "
//            + "     from b_monitor where status != '"+ DictConstant.DICT_B_MONITOR_STATUS_EIGHT +"'            "
//            + " group by schedule_id) t10 ON t1.id = t10.schedule_id                                           "
            + "    WHERE true                                                                                  "
            + "    	    and (t9.id = #{p1.id} or #{p1.id} is null)                                             "
            + "    	    and (t1.code like concat('%', #{p1.schedule_code}, '%') or #{p1.schedule_code} is null or #{p1.schedule_code} = '')"
            + "    	    and (t3.name like concat('%', #{p1.sku_name}, '%') or t9.name like concat('%', #{p1.sku_name}, '%') or  #{p1.sku_name} is null or  #{p1.sku_name} = '')"
            + "    	    and (t3.code like concat('%', #{p1.goods_code}, '%') or t9.code like concat('%', #{p1.goods_code}, '%') or #{p1.goods_code} is null or #{p1.goods_code} = '')"
            + "    	    and (t2.NAME like concat('%', #{p1.customer_name}, '%') or #{p1.customer_name} is null or #{p1.customer_name} = '') "
            + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
            + "     and (DATE_FORMAT(t1.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
            + "    <if test='p1.query_type == 1'>                                                              "
            + "      and t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + " '                        "
            + "     AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0                "
            + "    </if>                                                                                       "

            + "    <if test='p1.query_type == 2'>                                                              "
            + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
            + "    </if>                                                                                       "
            + "    ${p1.params.dataScopeAnnotation}  "
            + "         group by t1.code, t2.id, t3.id) tt1                                                    "

            + " </script> "
    })
    int selectScheduleExportNum(@Param("p1") BQtyLossScheduleReportVo param);

    /**
     * 监管任务 在途 损耗 明细
     * @param param 入参
     * @return int
     */
    @Select({
            " <script> "
                    + " ${p1.params.dataScopeAnnotation_with}                                                         "
                    + "    SELECT count(1)                                                                             "
                    + "    FROM                                                                                        "
                    + "    	b_monitor t                                                                                "
                    + "    	LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                           "
                    + "    	LEFT JOIN m_customer t2 ON t.customer_id = t2.id                                           "
                    + "    	LEFT JOIN m_goods_spec t3 ON t1.sku_id = t3.id                                             "
                    + "    	LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                          "
                    + "    	LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                      "
                    + "    	LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                         "
                    + "    	LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                    "
                    + "    	LEFT JOIN m_goods t9 ON t3.goods_id = t9.id                                                "
                    + "    WHERE true                                                                                  "
                    + "      and (t9.id = #{p1.id} or #{p1.id} is null)                                                "
                    + "   ${p1.params.dataScopeAnnotation}                                                             "
                    + "      and (t1.code like concat('%', #{p1.schedule_code}, '%') or #{p1.schedule_code} is null or #{p1.schedule_code} = '')"
                    + "      and (t.code like concat('%', #{p1.code}, '%') or #{p1.code} is null or #{p1.code} = '')   "
                    + "      and (t3.name like concat('%', #{p1.sku_name}, '%') or #{p1.sku_name} is null or #{p1.sku_name} = '')"
                    + "      and (t3.code like concat('%', #{p1.sku_code}, '%') or #{p1.sku_code} is null or #{p1.sku_code} = '')"
                    + "      and (t2.name like concat('%', #{p1.customer_name}, '%') or #{p1.customer_name} is null or #{p1.customer_name} = '')"
                    + "     and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')"
                    + "    <if test='p1.query_type == 1'>                                                              "
                    + "      and t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "'                         "
                    + "      AND ifnull( ifnull( t6.qty, t7.qty ) - ifnull( t4.qty, t5.qty ), 0 ) &gt; 0                "
                    + "    </if>                                                                                       "

                    + "    <if test='p1.query_type == 2'>                                                              "
                    + "      and t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    + "    </if>                                                                                       "
                    + " </script> "
    })
    int selectMonitorExportNum(@Param("p1") BQtyLossScheduleReportVo param);

    /**
     * 司机id查询监管任务
     */
    @Select("                                                                                                           "
            + "     SELECT                                                                                              "
            + "            t.*                                                                                          "
            + "       FROM                                                                                              "
            + "  	       b_monitor t                                                                                  "
            + "     where true                                                                                          "
            + "         and t.status != '" + DictConstant.DICT_B_MONITOR_STATUS_EIGHT + "'                              "
            + "         and (t.driver_id =  #{p1,jdbcType=INTEGER} or #{p1,jdbcType=INTEGER} is null)                   "
            + "     ")
    List<BMonitorEntity> selectByDriverId(@Param("p1") Integer id);

    /**
     * 车辆id查询监管任务
     */
    @Select("                                                                                                           "
            + "     SELECT                                                                                              "
            + "            t.*                                                                                          "
            + "       FROM                                                                                              "
            + "  	       b_monitor t                                                                                  "
            + "     where true                                                                                          "
            + "         and t.status != '" + DictConstant.DICT_B_MONITOR_STATUS_EIGHT + "'                              "
            + "         and (t.vehicle_id =  #{p1,jdbcType=INTEGER} or #{p1,jdbcType=INTEGER} is null)                  "
            + "     ")
    List<BMonitorEntity> selectByVehicleId(@Param("p1") Integer id);

    /**
     * 承运商id查询监管任务
     */
    @Select("                                                                                                           "
            + "     SELECT                                                                                              "
            + "            t.*                                                                                          "
            + "       FROM                                                                                              "
            + "  	       b_monitor t                                                                                  "
            + "     where true                                                                                          "
            + "         and t.status != '" + DictConstant.DICT_B_MONITOR_STATUS_EIGHT + "'                              "
            + "         and (t.customer_id =  #{p1,jdbcType=INTEGER} or #{p1,jdbcType=INTEGER} is null)                 "
            + "     ")
    List<BMonitorEntity> selectByCustomerId(@Param("p1") Integer id);

    @Select(" <script>   "
            + " ${p1.params.dataScopeAnnotation_with}                                                                   "
            + common_select
            + "  <if test='p1.active_tabs_index != null and p1.active_tabs_index == \"6\"'>                             "
            + "    inner join b_message t31 ON t31.serial_type = '" + SystemConstants.SERIAL_TYPE.B_MONITOR  + "'       "
            + "    and t31.serial_id = t.id                                                                             "
            + "  </if>                                                                                                  "
            + "  <if test='p1.active_tabs_index != null and p1.active_tabs_index == \"7\"'>                             "
            + "    inner join b_message t31 ON t31.serial_type = '" +  DictConstant.DICT_SYS_CODE_TYPE_B_MONITOR_UNAUDITED + "'"
            + "    and t31.serial_id = t.id                                                                             "
            + "  </if>                                                                                                  "
            + "  <if test='p1.active_tabs_index != null and p1.active_tabs_index == \"8\"'>                             "
            + "    inner join b_message t31 ON t31.serial_type = '" +  DictConstant.DICT_SYS_CODE_TYPE_M_MONITOR_LOSS + "'"
            + "    and t31.serial_id = t.id                                                                             "
            + "  </if>                                                                                                  "
            + "  where true                                                                                                                                                     "
            + "    and (t.status = #{p1.status,jdbcType=VARCHAR} or #{p1.status,jdbcType=VARCHAR} is null or #{p1.status,jdbcType=VARCHAR} ='')                                 "
            + "   <if test='p1.status_list != null and p1.status_list.length!=0' >                                                                                              "
            + "    and t.status in                                                                                                                                              "
            + "        <foreach collection='p1.status_list' item='item' index='index' open='(' separator=',' close=')'>                                                         "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "   <if test='p1.audit_status_list != null and p1.audit_status_list.length!=0' >                                                                                  "
            + "    and t.audit_status in                                                                                                                                        "
            + "        <foreach collection='p1.audit_status_list' item='item' index='index' open='(' separator=',' close=')'>                                                   "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "    and (t.code like concat('%',#{p1.code,jdbcType=VARCHAR},'%') or #{p1.code,jdbcType=VARCHAR} is null or #{p1.code,jdbcType=VARCHAR} = '')                     "
            + "    and (t4.code like concat('%',#{p1.schedule_code,jdbcType=VARCHAR},'%') or #{p1.schedule_code,jdbcType=VARCHAR} is null)                                      "
            + "    and (t.waybill_code like concat('%',#{p1.waybill_code,jdbcType=VARCHAR},'%') or #{p1.waybill_code,jdbcType=VARCHAR} is null)                                 "
            + "    and (concat(t7.name,t7.short_name,t7.code) like concat('%',#{p1.customer_name,jdbcType=VARCHAR},'%') or #{p1.customer_name,jdbcType=VARCHAR} is null)        "
            + "    and (concat(t8.code,t8.no) like concat('%',#{p1.vehicle_no,jdbcType=VARCHAR},'%') or #{p1.vehicle_no,jdbcType=VARCHAR} is null)                              "
            + "    and (concat(t9.name,t9.mobile_phone,t9.code) like concat('%',#{p1.driver_name,jdbcType=VARCHAR},'%') or #{p1.driver_name,jdbcType=VARCHAR} is null)          "
            + "    and (concat(ifnull(t10.contract_no,''),ifnull(t4.contract_no,'')) like concat('%',#{p1.contract_no,jdbcType=VARCHAR},'%') or #{p1.contract_no,jdbcType=VARCHAR} is null)"
            + "    and (concat(t11.name,t11.pm,t11.code,t11.spec) like concat('%',#{p1.goods_name,jdbcType=VARCHAR},'%') or #{p1.goods_name,jdbcType=VARCHAR} is null)          "
            + "    and (t4.out_type = #{p1.out_type,jdbcType=VARCHAR} or #{p1.out_type,jdbcType=VARCHAR} is null  or #{p1.out_type,jdbcType=VARCHAR} = '')                      "
            + "    and (t4.in_type = #{p1.in_type,jdbcType=VARCHAR} or #{p1.in_type,jdbcType=VARCHAR} is null or #{p1.in_type,jdbcType=VARCHAR} = '')                           "
            + "    and (concat(t6.name,t6.short_name) like concat('%',#{p1.out_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.out_warehouse_name,jdbcType=VARCHAR} is null)      "
            + "    and (concat(t5.name,t5.short_name) like concat('%',#{p1.in_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.in_warehouse_name,jdbcType=VARCHAR} is null)        "
            + "    and (t4.out_plan_code like concat('%',#{p1.out_plan_code,jdbcType=VARCHAR},'%') or #{p1.out_plan_code,jdbcType=VARCHAR} is null)                             "
            + "    and (t4.in_plan_code like concat('%',#{p1.in_plan_code,jdbcType=VARCHAR},'%') or #{p1.in_plan_code,jdbcType=VARCHAR} is null)                                "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.start_time,jdbcType=DATE} is null)              "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.over_time,jdbcType=DATE} is null)                "
            + "    and (t.settlement_status = #{p1.settlement_status,jdbcType=VARCHAR} or #{p1.settlement_status,jdbcType=VARCHAR} is null or #{p1.settlement_status,jdbcType=VARCHAR} ='')"
            + "    and (t.audit_status = #{p1.audit_status,jdbcType=VARCHAR} or #{p1.audit_status,jdbcType=VARCHAR} is null or #{p1.audit_status,jdbcType=VARCHAR} ='')         "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_start,jdbcType=DATE} is null)         "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_end,jdbcType=DATE} is null)             "
            + "    and (t.status != #{p1.un_status} or #{p1.un_status} is null or #{p1.un_status} = '')                                                                         "
            + "    and (t28.waybill_contract_no like concat('%', #{p1.waybill_contract_no}, '%') or #{p1.waybill_contract_no} is null or #{p1.waybill_contract_no} = '')        "
            + "            <if test='p1.in_warehouse_types != null and p1.in_warehouse_types.length!=0' >                                                                       "
            + "             and t5.warehouse_type in                                                                                                                            "
            + "                 <foreach collection='p1.in_warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                         "
            + "                  #{item}                                                                                                                                        "
            + "                 </foreach>                                                                                                                                      "
            + "            </if>                                                                                                                                                "
            + "            <if test='p1.out_warehouse_types != null and p1.out_warehouse_types.length!=0' >                                                                     "
            + "             and t6.warehouse_type in                                                                                                                            "
            + "                 <foreach collection='p1.out_warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                        "
            + "                  #{item}                                                                                                                                        "
            + "                 </foreach>                                                                                                                                      "
            + "            </if>                                                                                                                                                "
            + "    and (DATE_FORMAT(t.out_audit_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.out_audit_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.out_audit_start,jdbcType=DATE} is null)"
            + "    and (DATE_FORMAT(t.out_audit_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.out_audit_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.out_audit_end,jdbcType=DATE} is null)  "
            + "    and (DATE_FORMAT(t.in_audit_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_audit_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_audit_start,jdbcType=DATE} is null) "
            + "    and (DATE_FORMAT(t.in_audit_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_audit_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_audit_end,jdbcType=DATE} is null)     "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.c_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.c_time_start,jdbcType=DATE} is null)            "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.c_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.c_time_end,jdbcType=DATE} is null)                "
            + "    and (t27.name like concat('%', #{p1.out_audit_name}, '%') or #{p1.out_audit_name} is null or #{p1.out_audit_name} = '')                                      "
            + "    and (t26.name like concat('%', #{p1.in_audit_name}, '%') or #{p1.in_audit_name} is null or #{p1.in_audit_name} = '')                                         "
            + "    and (t30.code like concat('%', #{p1.container_code}, '%') or #{p1.container_code} is null or #{p1.container_code} = '')                                      "
            + "    and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                                                        "
            + "    and (t.is_sync = #{p1.is_sync,jdbcType=VARCHAR} or #{p1.is_sync,jdbcType=VARCHAR} is null or #{p1.is_sync,jdbcType=VARCHAR} ='')                             "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.b_schedule_time_start,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_start,jdbcType=DATE} is null)                       "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d' ) &lt;= DATE_FORMAT(#{p1.b_schedule_time_end,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_end,jdbcType=DATE} is null)                "
            // 监管任务是否有退货 2=否
            + "            <if test='p1.if_return_qty != null and p1.if_return_qty == 2' >                                                                                       "
            + "             and t35.qty is null                                                                                                                            "
            + "            </if>                                                                                                                                                "
            // 监管任务是否有退货 1= 是
            + "            <if test='p1.if_return_qty != null  and p1.if_return_qty == 1' >                                                                                      "
            + "             and t35.qty is not null                                                                                                                            "
            + "            </if>                                                                                                                                                "
            //  page页面查询条件 1=监管任务page查询 2=直采直销page查询
            + "            <if test='p1.if_page_list != null and p1.if_page_list == 1' >                                                                                       "
            + "             and t4.type not in ('"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"','"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"')                                           "
            + "            </if>                                                                                                                                               "
            // page页面查询条件 2=直采直销page查询
            + "            <if test='p1.if_page_list != null and p1.if_page_list == 2' >                                                                                         "
            + "             and t4.type in ('"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"','"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"')                                                 "
            + "             and (DATE_FORMAT(IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t.in_audit_time,t.out_audit_time) , '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.audit_time_start,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.audit_time_start,jdbcType=DATE} is null)                "
            + "             and (DATE_FORMAT(IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t.in_audit_time,t.out_audit_time) , '%Y-%m-%d' ) &lt;= DATE_FORMAT(#{p1.audit_time_end,jdbcType=DATE}, '%Y-%m-%d' )  or #{p1.audit_time_end,jdbcType=DATE} is null)                   "
            + "             and (IF(t4.type = '"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"',t26.name,t27.name) like concat('%',#{p1.audit_name,jdbcType=VARCHAR},'%') or #{p1.audit_name,jdbcType=VARCHAR} is null)                                      "
            + "            </if>                                                                                                                                                 "
            + "     ${p1.params.dataScopeAnnotation}                                                                                                                            "
            + "    ORDER BY ${p2} ${p3} ${p4}                                                                                                                                   "
            + "    limit ${(p1.pageCondition.current-1)*p1.pageCondition.size},  #{p1.pageCondition.size}                                                                       "
            + "   </script>   ")
    List<BMonitorVo> selectListByParam(@Param("p1") BMonitorVo searchCondition, @Param("p2") String sort,@Param("p3") String sortType,@Param("p4") String defaultSort);

    /**
     * 查询同步失败 和未同步的监管任务
     * @return
     */
    @Select(""
            +  "  SELECT                                                                                                "
            +  "    t.id                                                                                                "
            +  "  FROM                                                                                                  "
            +  "    b_monitor t                                                                                         "
            +  "  LEFT JOIN b_sync_status_error t1 ON t.id = t1.serial_id AND t1.serial_type = 'b_monitor'              "
            +  "  WHERE t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "'                                   "
            +  "  AND t.audit_status = '" + DictConstant.DICT_B_MONITOR_AUDIT_STATUS_TWO+ "'                            "
            +  "  AND t.customer_code = 'QY20220314147'                                                                 "
            +  "  AND (t1.`status` = '0' OR t1.`status` IS NULL)                                                        "
    )
    List<BMonitorVo> selectAll2Sync();

    @Select(""
            + " SELECT                                                                                                  "
            + "     t.id,                                                                                               "
            + "     t.code,                                                                                             "
            + "     case t.status when '" + DictConstant.DICT_B_MONITOR_STATUS_EIGHT + "' then '已作废' else if(t.audit_status = '"+ DictConstant.DICT_B_MONITOR_AUDIT_STATUS_TWO +"', '已审批', '未审批') end statusName,"
            + "     case t.status when '" + DictConstant.DICT_B_MONITOR_STATUS_EIGHT + "' then -1 else if(t.audit_status = '"+ DictConstant.DICT_B_MONITOR_AUDIT_STATUS_TWO +"', '1', '0') end statusId,"
            + "     t.code wmsCode,                                                                                     "
            + "     t13.order_no orderCode,                                                                             "
            + "     t13.carriage_contract_code contractCode,                                                            "
            + "     t1.contract_no contractNo,                                                                          "
            + "     t4.no  plateNum,                                                                                    "
            + "     t2.`code` in_warehouse_code,                                                                        "
            + "     t2.name in_warehouse_name,                                                                          "
            + "     t2.name receiptAddress,                                                                             "
            + "     t2.warehouse_type inWarehouseType,                                                                  "
            + "     t3.code out_warehouse_code,                                                                         "
            + "     t3.name out_warehouse_name,                                                                         "
            + "     t3.name sendAddress,                                                                                "
            + "     t3.warehouse_type outWarehouseTypes,                                                                "
            + "     t5.code sku_code,                                                                                   "
            + "     t5.name sku_name,                                                                                   "
            + "     t6.code goods_code,                                                                                 "
            + "     t6.name goodsName,                                                                                  "
            + "     ifnull(t7.qty,t8.qty) as receiptCount,                                                              "
            + "     ifnull(t9.qty,t10.qty) as sendCount,                                                                "
            + "     case when ifnull(t7.type,t8.type) = '"+ SystemConstants.MONITOR.B_MONITOR_UNLOAD +"' then 0         "
            + "                 else ifnull(ifnull(t9.qty,t10.qty) - ifnull(t7.qty,t8.qty), 0) end as  lossCount,       "
//            + "     t11.label audit_status_name,                                                                        "
            + "     t.status as monitorStatus,                                                                          "
            + "     t12.label monitorStatusName,                                                                        "
            + "     t14.name orgName,                                                                                   "
            + "     t14.short_name orgAbbr,                                                                             "
            + "     t14.credit_no creditNo,                                                                             "
            + "     t15.label modeTransportName,                                                                        "
            + "     t13.org_name companyAbbr,                                                                           "
            + "     t13.org_name companyName,                                                                           "
            + "     DATE_FORMAT(t.c_time, '%Y-%m-%d') inputDateStr,                                                     "
            + "     t.c_time inputDate,                                                                                 "
            + "     t.out_time                                                                                          "
            + " FROM                                                                                                    "
            + "    b_monitor t                                                                                          "
            + " LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                                        "
            + " LEFT JOIN m_warehouse t2 ON t1.in_warehouse_id = t2.id                                                  "
            + " LEFT JOIN m_warehouse t3 ON t1.out_warehouse_id = t3.id                                                 "
            + " LEFT JOIN m_vehicle t4 ON t.vehicle_id = t4.id                                                          "
            + " LEFT JOIN m_goods_spec t5 ON t1.sku_id = t5.id                                                          "
            + " LEFT JOIN m_goods t6 ON t5.goods_id = t6.id                                                             "
            + " LEFT JOIN b_monitor_in t7 ON t7.monitor_id = t.id                                                       "
            + " LEFT JOIN b_monitor_unload t8 ON t8.monitor_id = t.id                                                   "
            + " LEFT JOIN b_monitor_out t9 ON t9.monitor_id = t.id                                                      "
            + " LEFT JOIN b_monitor_delivery t10 ON t10.monitor_id = t.id                                               "
//            + " LEFT JOIN v_dict_info t11 ON t11.code = '"+DictConstant.DICT_B_MONITOR_AUDIT_STATUS+"' and t.audit_status = t11.dict_value"
            + " LEFT JOIN v_dict_info t12 ON t12.code = 'b_monitor_status' and t.status = t12.dict_value                "
            + " LEFT JOIN b_carriage_order t13 ON t13.id = t1.carriage_order_id                                         "
            + "  LEFT JOIN m_customer t14 ON t.customer_id = t14.id                                                     "
            + " LEFT JOIN v_dict_info t15 ON t15.code = 'b_schedule_transport_type' and t1.transport_type = t15.dict_value"
            + " WHERE t.id = #{p1}                                                                                      "
//            + " AND t.is_sync != '"+ DictConstant.DICT_B_MONITOR_IS_SYNC_N +"'                                               "
//            + " AND t13.id IS NOT NULL                                                                                  "
//            t.status = '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "'
//            + " AND t.audit_status = '" + DictConstant.DICT_B_MONITOR_AUDIT_STATUS_TWO+ "'                              "
    )
    ApiMonitorVo selectMonitor2Sync(@Param("p1") Integer id);

    @Select("SELECT id from b_monitor where container_id = #{p1} and status != '"+ DictConstant.DICT_B_MONITOR_STATUS_EIGHT +"'")
    List<Integer> selectActiveMonitorByContainerId(@Param("p1") Integer id);

    /**
     * 查询可以同步的监管任务
     * @param searchConditionList
     * @return
     */
    @Select("<script>"
            + " SELECT t.id from b_monitor t                                                                             "
            + " LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                        "
            + " WHERE t.is_sync != '"+ DictConstant.DICT_B_MONITOR_IS_SYNC_N +"'                                        "
            + " <if test='p1 != null and p1.size != 0'>                                                                 "
            + "   AND t.id in                                                                                           "
            + "   <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>                  "
            + "     #{item.id}                                                                                          "
            + "   </foreach>                                                                                            "
            + "  </if>                                                                                                  "
            + "</script>"
    )
    List<BMonitorVo> selectSyncData(@Param("p1") List<BMonitorVo> searchConditionList);

    /**
     * 根据 codeList 查询
     *
     * @param searchConditionList
     * @return
     */
    @Select(" <script>   "
            + "     SELECT                                                                                                                                      "
            + "            t14.code out_code,                                                                                                                   "
            + "            t.code,                                                                                                                              "
            + "            t15.extra_code out_extra_code                                                                                                        "
              + "       FROM                                                                                                                                    "
            + "  	        b_monitor t                                                                                                                         "
            + "  LEFT JOIN b_schedule t4 ON t4.id = t.schedule_id                                                                                               "
            + "  LEFT JOIN b_monitor_out t22 ON t22.monitor_id = t.id                                                                                           "
            + "  LEFT JOIN b_out t14 on t22.out_id = t14.id                                                                                                     "
            + "  LEFT JOIN b_out_plan t15 ON t4.out_plan_code = t15.code                                                                                        "
            + "  WHERE true                                                                                                                                     "
            + "   <if test='p1 != null and p1.size!=0' >                                                                                                        "
            + "    and t.code in                                                                                                                                "
            + "        <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>                                                     "
            + "         #{item}                                                                                                                                 "
            + "        </foreach>                                                                                                                               "
            + "   </if>                                                                                                                                         "
            + "   </script>   ")
    List<BMonitorVo> selectListByCodeList(@Param("p1") List<String> searchConditionList);

    @Select(""
            +  "  SELECT                                                                                                "
            +  "  	t.track_log,                                                                                        "
            +  "  	t.validate_log,                                                                                     "
            +  "  	t1.`no` vehicle_no,                                                                                 "
            +  "  	t.track_start_time,                                                                                "
            +  "  	t.track_end_time,                                                                                  "
            +  "  	t2.label vehicle_color                                                                              "
            +  "  FROM                                                                                                  "
            +  "  	b_monitor t                                                                                         "
            +  "  	LEFT JOIN m_vehicle t1 ON t.vehicle_id = t1.id                                                      "
            +  "  	LEFT JOIN v_dict_info t2 ON t1.no_color = t2.dict_value                                             "
            +  "  	AND t2.`code` = 'm_vehicle_no_color'                                                                "
            +  "  WHERE t.id = #{id}	                                                                                "
    )
    BMonitorVo selectValidateAndTrackLog(Integer id);

    @Select(""
            +  "  SELECT                                                                                                "
            +  "    t1.in_rule schedule_in_rule,                                                                        "
            +  "    t3.extra_code in_extra_code,                                                                        "
            +  "    t2.in_id in_id,                                                                                     "
            +  "    t2.delivery_id delivery_id                                                                              "
            +  "  FROM                                                                                                  "
            +  "    b_monitor t                                                                                         "
            +  "  LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                      "
            +  "  LEFT JOIN b_monitor_in t2 ON t.id = t2.monitor_id                                                     "
            +  "  LEFT JOIN b_in_plan_detail t3 ON t3.id = t1.in_plan_detail_id                                         "
            +  "  WHERE t.id = #{p1}                                                                                    "
    )
    BMonitorVo selectInByMonitorId(@Param("p1") Integer id);

    /**
     * 根据 物流订单ID 查询非作废的监管任务
     * @param scheduleId
     * @return
     */
    @Select(""
            + "  SELECT                                                                                                 "
            + "    id                                                                                                   "
            + "  FROM b_monitor                                                                                         "
            + "  WHERE schedule_id = #{p1}                                                                              "
            + "  AND status != '"+ DictConstant.DICT_B_MONITOR_STATUS_EIGHT +"'                                         "
            + "  union all                                                                                              "
            + "  SELECT                                                                                                 "
            + "    id                                                                                                   "
            + "  FROM b_monitor_backup                                                                                  "
            + "  WHERE schedule_id = #{p1}                                                                              "
    )
    List<Integer> selectNotCancelMonitorByScheduleId(Integer scheduleId);


    /**
     * 在途汇总 包含铁路虚拟库
     * @param param
     * @param page
     * @return
     */
    @Select({
            " SELECT                                                                                                                                                                      "
            +" 	sum(temp.qty) as qty,                                                                                                                                                     "
            +" 	temp.goods_prop as goods_prop,                                                                                                                                            "
            +" 	temp.id as id                                                                                                                                                             "
            +" FROM(	                                                                                                                                                                  "
            +"  ${p1.params.dataScopeAnnotation_with}                                                                                                                                     "
            +" 	SELECT                                                                                                                                                                    "
            +" 		sum(ifnull( t6.qty, t7.qty )) - sum(ifnull(t9.qty,0))AS qty,                                                                                                               "
            +" 		t8.NAME AS goods_prop,                                                                                                                                                "
            +" 		t8.id id                                                                                                                                                              "
            +" 	FROM                                                                                                                                                                      "
            +" 		b_monitor t                                                                                                                                                           "
            +" 		LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                                                                                                      "
            +" 		LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                                                                                        "
            +" 		LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                                                                                                           "
            +" 		LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                                                                                                     "
            +" 		LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                                                                                                 "
            +" 		LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                                                                                                    "
            +" 		LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                                                                                               "
            +" 		LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                                                                                                  "
            +"      LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                                               "
            +"      AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                                                "
            +" 	WHERE TRUE                                                                                                                                                                "
            +" 		AND (t8.NAME LIKE concat('%',#{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')                                                             "
            +" 		AND (DATE_FORMAT( t.c_time, '%Y-%m-%d' ) >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                                                                   "
            +" 		${p1.params.dataScopeAnnotation}                                                                                                                                      "
            +" 		AND t.STATUS IN ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"' )"
            +" 		GROUP BY t8.id                                                                                                                                                        "
            +" 		UNION ALL                                                                                                                                                             "
            +" 	SELECT                                                                                                                                                                    "
            +" 		SUM( t.qty_avaible ) qty,                                                                                                                                             "
            +" 		t2.NAME AS goods_prop,                                                                                                                                                "
            +" 		t2.id                                                                                                                                                                 "
            +" 	FROM                                                                                                                                                                      "
            +" 		m_inventory t                                                                                                                                                         "
            +" 		LEFT JOIN m_goods_spec t1 ON t.sku_id = t1.id                                                                                                                         "
            +" 		LEFT JOIN m_goods_spec_prop t2 ON t2.id = t1.prop_id                                                                                                                  "
            +" 		LEFT JOIN m_warehouse t3 ON t3.id = t.warehouse_id                                                                                                                    "
            +" 		WHERE TRUE                                                                                                                                                            "
            +" 		AND	 t3.warehouse_type = '" + DictConstant.DICT_M_WAREHOUSE_TYPE_TL + "'                                                                                              "
            +" 		AND (t2.NAME LIKE concat('%',#{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')                                                             "
            +" 		GROUP BY t2.id ) AS temp GROUP BY temp.id                                                                                                                             "
    })
    IPage<BContractReportVo> queryQtyInventorTotalList(@Param("p1") BContractReportVo param, Page<BMonitorEntity> page);


    /**
     * 在途汇总 包含铁路虚拟库 合计
     * @param param
     * @param page
     * @return
     */
    @Select({
            " SELECT                                                                                                                                                                              "
                    +" 	sum(temp.qty) as qty,                                                                                                                                                     "
                    +" 	temp.goods_prop as goods_prop,                                                                                                                                            "
                    +" 	temp.id as id                                                                                                                                                             "
                    +" FROM(	                                                                                                                                                                  "
                    +"  ${p1.params.dataScopeAnnotation_with}                                                                                                                                     "
                    +" 	SELECT                                                                                                                                                                    "
                    +" 		sum(ifnull( t6.qty, t7.qty )) - sum(ifnull(t9.qty,0)) AS qty,                                                                                                           "
                    +" 		t8.NAME AS goods_prop,                                                                                                                                                "
                    +" 		t8.id id                                                                                                                                                              "
                    +" 	FROM                                                                                                                                                                      "
                    +" 		b_monitor t                                                                                                                                                           "
                    +" 		LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                                                                                                      "
                    +" 		LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                                                                                        "
                    +" 		LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                                                                                                           "
                    +" 		LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                                                                                                     "
                    +" 		LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                                                                                                 "
                    +" 		LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                                                                                                    "
                    +" 		LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                                                                                               "
                    +" 		LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                                                                                                  "
                    +"      LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    +"      AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                    "
                    +" 	WHERE TRUE                                                                                                                                                              "
                    +" 		AND (t8.NAME LIKE concat('%',#{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')                                                             "
                    +" 		AND (DATE_FORMAT( t.c_time, '%Y-%m-%d' ) >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                                                               "
                    +" 		${p1.params.dataScopeAnnotation}                                                                                                                                   "
                    +" 		AND t.STATUS IN ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"' )"
                    +" 		GROUP BY t8.id                                                                                                                                                        "
                    +" 		UNION ALL                                                                                                                                                             "
                    +" 	SELECT                                                                                                                                                                    "
                    +" 		SUM( t.qty_avaible ) qty,                                                                                                                                             "
                    +" 		t2.NAME AS goods_prop,                                                                                                                                                "
                    +" 		t2.id                                                                                                                                                                 "
                    +" 	FROM                                                                                                                                                                      "
                    +" 		m_inventory t                                                                                                                                                         "
                    +" 		LEFT JOIN m_goods_spec t1 ON t.sku_id = t1.id                                                                                                                         "
                    +" 		LEFT JOIN m_goods_spec_prop t2 ON t2.id = t1.prop_id                                                                                                                  "
                    +" 		LEFT JOIN m_warehouse t3 ON t3.id = t.warehouse_id                                                                                                                    "
                    +" 		WHERE TRUE                                                                                                                                                            "
                    +" 		AND	 t3.warehouse_type = '" + DictConstant.DICT_M_WAREHOUSE_TYPE_TL + "'                                                                                              "
                    +" 		AND (t2.NAME LIKE concat('%',#{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')                                                             "
                    +" 		GROUP BY t2.id ) AS temp                                                                                                                                   "
    })
    BContractReportVo queryQtyInventorSumList(@Param("p1")BContractReportVo param);


    /**
     * 在途明细 包含铁路虚拟库
     * @param param
     * @param page
     * @return
     */
    @Select({
            " <script>                                                                                                             "
               +"SELECT                                                                                                            "
               +"		SUM(temp.qty) as qty,                                                                                      "
               +"		SUM(temp.qty_inventory) as qty_inventory,                                                                  "
               +"		SUM(temp.return_qty) as return_qty,                                                                        "
               +"		ifnull(SUM(temp.qty)+SUM(temp.qty_inventory),0) as count_qty,                                              "
               +"		temp.goods_name,                                                                                           "
               +"		temp.goods_code,                                                                                           "
               +"		temp.id_num                                                                                                "
               +"from(                                                                                                             "
               +" ${p1.params.dataScopeAnnotation_with}                                                                            "
               +"	SELECT                                                                                                         "
               +"		sum(ifnull( t6.qty, t7.qty )) -sum(ifnull(t9.qty,0)) AS qty,                                                "
               +"		sum(ifnull(t9.qty,0)) AS return_qty,                                                                  "
               +"		0 AS qty_inventory,                                                                                        "
               +"		t3.NAME AS goods_name,                                                                                     "
               +"		t3.CODE goods_code,                                                                                        "
               +"		t3.id id_num                                                                                               "
               +"	FROM                                                                                                           "
               +"		b_monitor t                                                                                                "
               +"		LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                                           "
               +"		LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                             "
               +"		LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                                                "
               +"		LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                                          "
               +"		LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                                      "
               +"		LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                                         "
               +"		LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                                    "
               +"		LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                                       "
               +"       LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
               +"       AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
               +"	WHERE                                                                                                          "
               +"	TRUE                                                                                                           "
               +"		AND (t3.NAME LIKE CONCAT('%',#{p1.goods_name}, '%') or #{p1.goods_name} is null or #{p1.goods_name} = '' ) "
               +"		AND (t8.NAME LIKE concat('%',#{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')  "
               +"	    AND (DATE_FORMAT( t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')      "
               +"      AND t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
               +"   ${p1.params.dataScopeAnnotation}  "
               +"		GROUP BY                                                                                                   "
               +"		t3.id                                                                                                      "
               +"	union all                                                                                                      "
               +"	SELECT                                                                                                         "
               +"		0 as qty,                                                                                                  "
               +"		0 AS return_qty,                                                                                           "
               +"		SUM( t.qty_avaible ) AS qty_inventory,                                                                     "
               +"		t2.NAME AS goods_name,                                                                                     "
               +"		t2.CODE AS goods_code,                                                                                     "
               +"		t2.id AS id_num                                                                                            "
               +"	FROM                                                                                                           "
               +"		m_inventory t                                                                                              "
               +"		LEFT JOIN m_goods_spec t1 ON t.sku_id = t1.id                                                              "
               +"		LEFT JOIN m_goods t2 ON t1.goods_id = t2.id                                                                "
               +"		LEFT JOIN m_warehouse t3 ON t3.id = t.warehouse_id                                                         "
               +"		LEFT JOIN m_goods_spec_prop t4 ON t4.id = t1.prop_id                                                       "
               +"	WHERE                                                                                                          "
               +"	TRUE                                                                                                           "
               +"		AND t3.warehouse_type = '" + DictConstant.DICT_M_WAREHOUSE_TYPE_TL + "'                                    "
               +"		AND (t2.NAME LIKE CONCAT('%',#{p1.goods_name}, '%') or #{p1.goods_name} is null or #{p1.goods_name} = '' ) "
               +"		AND (t4.NAME LIKE concat('%',#{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')  "
               +"	GROUP BY                                                                                                       "
               +"		t2.id) AS temp GROUP BY temp.id_num                                                                        "
               +" </script>                                                                                                        "
    })
    IPage<BContractReportVo> queryQtyInventorLossList(@Param("p1") BContractReportVo searchCondition, Page<BMonitorEntity> pageCondition);


    /**
     * 在途明细 包含铁路虚拟库合计
     * @param param
     * @param page
     * @return
     */
    @Select({
            " <script>                                                                                                                 "
                    +"SELECT                                                                                                           "
                    +"		SUM(temp.qty) as qty,                                                                                      "
                    +"		SUM(temp.qty_inventory) as qty_inventory                                                                   "
                    +"from(                                                                                                            "
                    +" ${p1.params.dataScopeAnnotation_with}                                                                           "
                    +"	SELECT                                                                                                         "
                    +"		sum(ifnull( t6.qty, t7.qty )) - sum(ifnull(t9.qty,0)) AS qty,                                                                      "
                    +"		0 AS qty_inventory                                                                                         "
                    +"	FROM                                                                                                           "
                    +"		b_monitor t                                                                                                "
                    +"		LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                                           "
                    +"		LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                             "
                    +"		LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                                                "
                    +"		LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                                          "
                    +"		LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                                      "
                    +"		LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                                         "
                    +"		LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                                    "
                    +"		LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                                       "
                    +"      LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    +"      AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                    "
                    +"	WHERE                                                                                                          "
                    +"	TRUE                                                                                                           "
                    +"		AND (t3.NAME LIKE CONCAT('%',#{p1.goods_name}, '%') or #{p1.goods_name} is null or #{p1.goods_name} = '' ) "
                    +"		AND (t8.NAME LIKE concat('%',#{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')  "
                    +"	    AND (DATE_FORMAT( t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')      "
                    +"      AND t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    +"   ${p1.params.dataScopeAnnotation}  "
                    +"	union all                                                                                                      "
                    +"	SELECT                                                                                                         "
                    +"		0 as qty,                                                                                                  "
                    +"		SUM( t.qty_avaible ) AS qty_inventory                                                                     "
                    +"	FROM                                                                                                           "
                    +"		m_inventory t                                                                                              "
                    +"		LEFT JOIN m_goods_spec t1 ON t.sku_id = t1.id                                                              "
                    +"		LEFT JOIN m_goods t2 ON t1.goods_id = t2.id                                                                "
                    +"		LEFT JOIN m_warehouse t3 ON t3.id = t.warehouse_id                                                         "
                    +"		LEFT JOIN m_goods_spec_prop t4 ON t4.id = t1.prop_id                                                       "
                    +"	WHERE                                                                                                          "
                    +"	TRUE                                                                                                           "
                    +"		AND t3.warehouse_type = '" + DictConstant.DICT_M_WAREHOUSE_TYPE_TL + "'                                    "
                    +"		AND (t2.NAME LIKE CONCAT('%',#{p1.goods_name}, '%') or #{p1.goods_name} is null or #{p1.goods_name} = '' ) "
                    +"		AND (t4.NAME LIKE concat('%',#{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')  "
                    +"		) AS temp                                                                                                  "
                    +" </script>                                                                                                       "
    })
    BContractReportVo queryQtyInventorLossListSum(@Param("p1")BContractReportVo param);

    @Select({
            " SELECT                                                                                                                                                                     "
                    +" 	sum(temp.qty) as qty,                                                                                                                                                                      "
                    +" 	temp.goods_prop as goods_prop,                                                                                                                                                               "
                    +" 	temp.id as id,                                                                                                                                                                        "
                    +" 	@row_num:= @row_num+ 1 as no                                                                                                                                                                        "
                    +" FROM(	                                                                                                                                                                  "
                    +"  ${p1.params.dataScopeAnnotation_with}                                                                                                                                   "
                    +" 	SELECT                                                                                                                                                                    "
                    +" 		sum(ifnull( t6.qty, t7.qty ))- sum(ifnull(t9.qty,0)) AS qty,                                                                                                                                     "
                    +" 		t8.NAME AS goods_prop,                                                                                                                                                "
                    +" 		t8.id id                                                                                                                                                              "
                    +" 	FROM                                                                                                                                                                      "
                    +" 		b_monitor t                                                                                                                                                           "
                    +" 		LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                                                                                                      "
                    +" 		LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                                                                                        "
                    +" 		LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                                                                                                           "
                    +" 		LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                                                                                                     "
                    +" 		LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                                                                                                 "
                    +" 		LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                                                                                                    "
                    +" 		LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                                                                                               "
                    +" 		LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                                                                                                  "
                    +"      LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    +"      AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                    "
                    +" 	WHERE TRUE                                                                                                                                                              "
                    +" 		AND (t8.NAME LIKE concat('%',#{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')                                                             "
                    +" 		AND (DATE_FORMAT( t.c_time, '%Y-%m-%d' ) >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                                                               "
                    +" 		${p1.params.dataScopeAnnotation}                                                                                                                                   "
                    +" 		AND t.STATUS IN ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"' )"
                    +" 		GROUP BY t8.id                                                                                                                                                        "
                    +" 		UNION ALL                                                                                                                                                             "
                    +" 	SELECT                                                                                                                                                                    "
                    +" 		SUM( t.qty_avaible ) qty,                                                                                                                                             "
                    +" 		t2.NAME AS goods_prop,                                                                                                                                                "
                    +" 		t2.id                                                                                                                                                                 "
                    +" 	FROM                                                                                                                                                                      "
                    +" 		m_inventory t                                                                                                                                                         "
                    +" 		LEFT JOIN m_goods_spec t1 ON t.sku_id = t1.id                                                                                                                         "
                    +" 		LEFT JOIN m_goods_spec_prop t2 ON t2.id = t1.prop_id                                                                                                                  "
                    +" 		LEFT JOIN m_warehouse t3 ON t3.id = t.warehouse_id                                                                                                                    "
                    +" 		WHERE TRUE                                                                                                                                                            "
                    +" 		AND	 t3.warehouse_type = '" + DictConstant.DICT_M_WAREHOUSE_TYPE_TL + "'                                                                                              "
                    +" 		AND (t2.NAME LIKE concat('%',#{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')                                                             "
                    +" 		GROUP BY t2.id ) AS temp                                                                                                                                    "
                    +" 		,(select @row_num:=0) tt2  GROUP BY temp.id                                                                                                                                                                                              "
    })
    List<BQtyInTransitExportVo> queryQtyOnWayByInventorAllExportAll(@Param("p1")BContractReportVo param);

    @Select({ " <script>                                                                                                "
                   + " SELECT                                                                                                                                                                     "
                    +" 	sum(temp.qty) as qty,                                                                                                                                                                      "
                    +" 	temp.goods_prop as goods_prop,                                                                                                                                                               "
                    +" 	temp.id as id,                                                                                                                                                                        "
                    +" 	@row_num:= @row_num+ 1 as no                                                                                                                                                                        "
                    +" FROM(	                                                                                                                                                                  "
                    +" 	SELECT                                                                                                                                                                    "
                    +" 		sum(ifnull( t6.qty, t7.qty )) - sum(ifnull(t9.qty,0))  AS qty,                                                                                                                                     "
                    +" 		t8.NAME AS goods_prop,                                                                                                                                                "
                    +" 		t8.id id                                                                                                                                                              "
                    +" 	FROM                                                                                                                                                                      "
                    +" 		b_monitor t                                                                                                                                                           "
                    +" 		LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                                                                                                      "
                    +" 		LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                                                                                        "
                    +" 		LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                                                                                                           "
                    +" 		LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                                                                                                     "
                    +" 		LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                                                                                                 "
                    +" 		LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                                                                                                    "
                    +" 		LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                                                                                               "
                    +" 		LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                                                                                                  "
                    +"      LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    +"      AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                    "
                    +" 	WHERE TRUE                                                                                                                                                              "
                    +" 		AND t.STATUS IN ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"' )"
                    +" 		GROUP BY t8.id                                                                                                                                                        "
                    +" 		UNION ALL                                                                                                                                                             "
                    +" 	SELECT                                                                                                                                                                    "
                    +" 		SUM( t.qty_avaible ) qty,                                                                                                                                             "
                    +" 		t2.NAME AS goods_prop,                                                                                                                                                "
                    +" 		t2.id                                                                                                                                                                 "
                    +" 	FROM                                                                                                                                                                      "
                    +" 		m_inventory t                                                                                                                                                         "
                    +" 		LEFT JOIN m_goods_spec t1 ON t.sku_id = t1.id                                                                                                                         "
                    +" 		LEFT JOIN m_goods_spec_prop t2 ON t2.id = t1.prop_id                                                                                                                  "
                    +" 		LEFT JOIN m_warehouse t3 ON t3.id = t.warehouse_id                                                                                                                    "
                    +" 		WHERE TRUE                                                                                                                                                            "
                    +" 		AND	 t3.warehouse_type = '" + DictConstant.DICT_M_WAREHOUSE_TYPE_TL + "'                                                                                              "
                    +" 		GROUP BY t2.id ) AS temp,(select @row_num:=0) tt2   where true                                                                                                                               "
                    +"    <if test='p1 != null and p1.size != 0'>                                                    "
                    +"     AND temp.id in                                                                             "
                    +"      <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>     "
                    +"          #{item.id,jdbcType=INTEGER}                                                                          "
                    +"      </foreach>                                                                               "
                    +"    </if>                                                                                       "
                    +" 		  GROUP BY temp.id                                                                                                                                                                                              "
                    +" </script>                                                                                                        "
    })
    List<BQtyInTransitExportVo> queryQtyOnWayByInventorExport(@Param("p1")List<BContractReportVo> param);

    @Select({
            " <script>                                                                                                "
                    +"SELECT                                                                                                           "
                    +"		SUM(temp.qty) as qty,                                                                                     "
                    +"		SUM(temp.qty_inventory) as qty_inventory,                                                                  "
                    +"		ifnull(SUM(temp.qty)+SUM(temp.qty_inventory),0) as count_qty,                                              "
                    +"		temp.goods_name,                                                                                           "
                    +"		temp.goods_code,                                                                                           "
                    +"		temp.id_num,                                                                                                "
                    +"		@row_num:= @row_num+ 1 as no                                                                                "
                    +"from(                                                                                                             "
                    +" ${p1.params.dataScopeAnnotation_with}                                                                            "
                    +"	SELECT                                                                                                         "
                    +"		sum(ifnull( t6.qty, t7.qty ))-sum(ifnull(t9.qty,0)) AS qty,                                                                      "
                    +"		0 AS qty_inventory,                                                                                        "
                    +"		t3.NAME AS goods_name,                                                                                     "
                    +"		t3.CODE goods_code,                                                                                        "
                    +"		t3.id id_num                                                                                               "
                    +"	FROM                                                                                                           "
                    +"		b_monitor t                                                                                                "
                    +"		LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                                           "
                    +"		LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                             "
                    +"		LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                                                "
                    +"		LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                                          "
                    +"		LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                                      "
                    +"		LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                                         "
                    +"		LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                                    "
                    +"		LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                                       "
                    +"      LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
                    +"      AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                    "
                    +"	WHERE                                                                                                          "
                    +"	TRUE                                                                                                           "
                    +"		AND (t3.NAME LIKE CONCAT('%',#{p1.goods_name}, '%') or #{p1.goods_name} is null or #{p1.goods_name} = '' ) "
                    +"		AND (t8.NAME LIKE concat('%',#{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')  "
                    +"	    AND (DATE_FORMAT( t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')      "
                    +"      AND t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
                    +"   ${p1.params.dataScopeAnnotation}  "
                    +"		GROUP BY                                                                                                   "
                    +"		t3.id                                                                                                      "
                    +"	union all                                                                                                      "
                    +"	SELECT                                                                                                         "
                    +"		0 as qty,                                                                                                  "
                    +"		SUM( t.qty_avaible ) AS qty_inventory,                                                                     "
                    +"		t2.NAME AS goods_name,                                                                                     "
                    +"		t2.CODE AS goods_code,                                                                                     "
                    +"		t2.id AS id_num                                                                                            "
                    +"	FROM                                                                                                           "
                    +"		m_inventory t                                                                                              "
                    +"		LEFT JOIN m_goods_spec t1 ON t.sku_id = t1.id                                                              "
                    +"		LEFT JOIN m_goods t2 ON t1.goods_id = t2.id                                                                "
                    +"		LEFT JOIN m_warehouse t3 ON t3.id = t.warehouse_id                                                         "
                    +"		LEFT JOIN m_goods_spec_prop t4 ON t4.id = t1.prop_id                                                       "
                    +"	WHERE                                                                                                          "
                    +"	TRUE                                                                                                           "
                    +"		AND t3.warehouse_type = '" + DictConstant.DICT_M_WAREHOUSE_TYPE_TL + "'                                    "
                    +"		AND (t2.NAME LIKE CONCAT('%',#{p1.goods_name}, '%') or #{p1.goods_name} is null or #{p1.goods_name} = '' ) "
                    +"		AND (t4.NAME LIKE concat('%',#{p1.goods_prop}, '%') or #{p1.goods_prop} is null or #{p1.goods_prop} = '')  "
                    +"	GROUP BY                                                                                                       "
                    +"		t2.id) AS temp ,(select @row_num:=0) tt2  GROUP BY temp.id_num                                                                        "
                    +" </script>                                                                                                        "
    })
    List<BInTransitReportExportVo> queryOnWayByInventorListExportAll(@Param("p1")BContractReportVo param);


    @Select({" <script>                                                                                                "
            +"SELECT                                                                                                           "
            +"		SUM(temp.qty) as qty,                                                                                     "
            +"		SUM(temp.qty_inventory) as qty_inventory,                                                                  "
            +"		ifnull(SUM(temp.qty)+SUM(temp.qty_inventory),0) as count_qty,                                              "
            +"		temp.goods_name,                                                                                           "
            +"		temp.goods_code,                                                                                           "
            +"		temp.id_num,                                                                                                "
            +"		@row_num:= @row_num+ 1 as no                                                                                "
            +"from(                                                                                                             "
            +"	SELECT                                                                                                         "
            +"		sum(ifnull( t6.qty, t7.qty )) - sum(ifnull(t9.qty,0)) AS qty,                                                                      "
            +"		0 AS qty_inventory,                                                                                        "
            +"		t3.NAME AS goods_name,                                                                                     "
            +"		t3.CODE goods_code,                                                                                        "
            +"		t3.id id_num                                                                                               "
            +"	FROM                                                                                                           "
            +"		b_monitor t                                                                                                "
            +"		LEFT JOIN b_schedule t1 ON t1.id = t.schedule_id                                                           "
            +"		LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                             "
            +"		LEFT JOIN m_goods t3 ON t2.goods_id = t3.id                                                                "
            +"		LEFT JOIN b_monitor_in t4 ON t4.monitor_id = t.id                                                          "
            +"		LEFT JOIN b_monitor_unload t5 ON t5.monitor_id = t.id                                                      "
            +"		LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                                         "
            +"		LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                                    "
            +"		LEFT JOIN m_goods_spec_prop t8 ON t8.id = t2.prop_id                                                       "
            +"      LEFT JOIN b_return_relation t9 ON t9.serial_id = t.id AND t9.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
            +"      AND  t9.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                    "
            +"	WHERE                                                                                                          "
            +"	TRUE                                                                                                           "
            +"      AND t.status in ( '" + DictConstant.DICT_B_MONITOR_STATUS_FOUR + "', '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"')"
            +"		GROUP BY                                                                                                   "
            +"		t3.id                                                                                                      "
            +"	union all                                                                                                      "
            +"	SELECT                                                                                                         "
            +"		0 as qty,                                                                                                  "
            +"		SUM( t.qty_avaible ) AS qty_inventory,                                                                     "
            +"		t2.NAME AS goods_name,                                                                                     "
            +"		t2.CODE AS goods_code,                                                                                     "
            +"		t2.id AS id_num                                                                                            "
            +"	FROM                                                                                                           "
            +"		m_inventory t                                                                                              "
            +"		LEFT JOIN m_goods_spec t1 ON t.sku_id = t1.id                                                              "
            +"		LEFT JOIN m_goods t2 ON t1.goods_id = t2.id                                                                "
            +"		LEFT JOIN m_warehouse t3 ON t3.id = t.warehouse_id                                                         "
            +"		LEFT JOIN m_goods_spec_prop t4 ON t4.id = t1.prop_id                                                       "
            +"	WHERE                                                                                                          "
            +"	TRUE                                                                                                           "
            +"		AND t3.warehouse_type = '" + DictConstant.DICT_M_WAREHOUSE_TYPE_TL + "'                                    "
            +"	GROUP BY                                                                                                       "
            +"		t2.id) AS temp ,(select @row_num:=0) tt2  where true                                               "
            +"    <if test='p1 != null and p1.size != 0'>                                                    "
            +"     AND temp.id_num in                                                                             "
            +"      <foreach collection='p1' item='item' index='index' open='(' separator=',' close=')'>     "
            +"          #{item.id_num}                                                                           "
            +"      </foreach>                                                                               "
            +"    </if>                                                                                       "
            +"     GROUP BY temp.id_num                                                                                        "
            +" </script>                                                                                                        "
    })
    List<BInTransitReportExportVo> queryOnWayByInventorListExport(@Param("p1")List<BContractReportVo> param);

    @Select("SELECT                                                                                         "
            +" DATE_FORMAT(t1.u_time, '%Y年%m月%d日 %H:%i:%s') as u_time,                                    "
            +" t1.*,                                                                                        "
            +" t1.file_name as file_title,                                                                  "
            +" t4.name as u_name,                                                                           "
            +" t5.login_name as login_name                                                                  "
            +" FROM                                                                                         "
            +"        s_file_info t1                                                                        "
            +" LEFT JOIN s_file t2 ON t2.id = t1.f_id                                                       "
            +" LEFT JOIN b_return_relation t3 ON t3.files_id = t2.id                                        "
            +" LEFT JOIN m_staff t4 ON t1.c_id = t4.id                                                      "
            +" LEFT JOIN m_user t5 ON t4.id = t5.staff_id                                                   "
            +" where TRUE                                                                                   "
            +"  and t3.serial_id = #{p1} and t3.serial_type = #{p2}                                         "
            +"  and t3.status = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                       "
    )
    List<BMonitorPreviewFileVo> getMonitorByReturnFile(@Param("p1") Integer id, @Param("p2") String dictBReturnRelation);

    /**
     * 页面导出列表
     */
    @Select(" <script>   "
            + common_select_export
            + "   where true                                                                                            "
            + "   <if test='p1.ids != null and p1.ids.size!=0' >                                                                "
            + "    and t.id in                                                                                          "
            + "        <foreach collection='p1.ids' item='item' index='index' open='(' separator=',' close=')'>             "
            + "         #{item,jdbcType=INTEGER}                                                                     "
            + "        </foreach>                                                                                       "
            + "   </if>                                                                                                 "
            + "    </script>    ")
    List<BMonitorDirectExportVo> exportDirectData(@Param("p1")BMonitorVo searchCondition);



    /**
     * 页面查询列表
     */
    @Select(" <script>   "
            + " ${p1.params.dataScopeAnnotation_with}                                                                                               "
            + common_select_export
            + "  where true                                                                                                                                                     "
            + "    and (t.status = #{p1.status,jdbcType=VARCHAR} or #{p1.status,jdbcType=VARCHAR} is null or #{p1.status,jdbcType=VARCHAR} ='')                                 "
            + "   <if test='p1.status_list != null and p1.status_list.length!=0' >                                                                                              "
            + "    and t.status in                                                                                                                                              "
            + "        <foreach collection='p1.status_list' item='item' index='index' open='(' separator=',' close=')'>                                                         "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "   <if test='p1.audit_status_list != null and p1.audit_status_list.length!=0' >                                                                                  "
            + "    and t.audit_status in                                                                                                                                        "
            + "        <foreach collection='p1.audit_status_list' item='item' index='index' open='(' separator=',' close=')'>                                                   "
            + "         #{item}                                                                                                                                                 "
            + "        </foreach>                                                                                                                                               "
            + "   </if>                                                                                                                                                         "
            + "  <if test='p1.active_tabs_index != null and p1.active_tabs_index == \"8\"'>                                                                                     "
            + "    inner join b_message t31 ON t31.serial_type = '" +  DictConstant.DICT_SYS_CODE_TYPE_M_MONITOR_LOSS + "'                                                      "
            + "    and t31.serial_id = t.id                                                                                                                                     "
            + "  </if>                                                                                                                                                          "
            + "    and (t.code like concat('%',#{p1.code,jdbcType=VARCHAR},'%') or #{p1.code,jdbcType=VARCHAR} is null or #{p1.code,jdbcType=VARCHAR} = '')                     "
            + "    and (t4.code like concat('%',#{p1.schedule_code,jdbcType=VARCHAR},'%') or #{p1.schedule_code,jdbcType=VARCHAR} is null)                                      "
            + "    and (t.waybill_code like concat('%',#{p1.waybill_code,jdbcType=VARCHAR},'%') or #{p1.waybill_code,jdbcType=VARCHAR} is null)                                 "
            + "    and (concat(t7.name,t7.short_name,t7.code) like concat('%',#{p1.customer_name,jdbcType=VARCHAR},'%') or #{p1.customer_name,jdbcType=VARCHAR} is null)        "
            + "    and (concat(t8.code,t8.no) like concat('%',#{p1.vehicle_no,jdbcType=VARCHAR},'%') or #{p1.vehicle_no,jdbcType=VARCHAR} is null)                              "
            + "    and (concat(t9.name,t9.mobile_phone,t9.code) like concat('%',#{p1.driver_name,jdbcType=VARCHAR},'%') or #{p1.driver_name,jdbcType=VARCHAR} is null)          "
            + "    and (concat(ifnull(t10.contract_no,''),ifnull(t4.contract_no,'')) like concat('%',#{p1.contract_no,jdbcType=VARCHAR},'%') or #{p1.contract_no,jdbcType=VARCHAR} is null)                                  "
            + "    and (concat(t11.name,t11.pm,t11.code,t11.spec) like concat('%',#{p1.goods_name,jdbcType=VARCHAR},'%') or #{p1.goods_name,jdbcType=VARCHAR} is null)          "
            + "    and (t4.out_type = #{p1.out_type,jdbcType=VARCHAR} or #{p1.out_type,jdbcType=VARCHAR} is null  or #{p1.out_type,jdbcType=VARCHAR} = '')                      "
            + "    and (t4.in_type = #{p1.in_type,jdbcType=VARCHAR} or #{p1.in_type,jdbcType=VARCHAR} is null or #{p1.in_type,jdbcType=VARCHAR} = '')                           "
            + "    and (concat(t6.name,t6.short_name) like concat('%',#{p1.out_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.out_warehouse_name,jdbcType=VARCHAR} is null)      "
            + "    and (concat(t5.name,t5.short_name) like concat('%',#{p1.in_warehouse_name,jdbcType=VARCHAR},'%') or #{p1.in_warehouse_name,jdbcType=VARCHAR} is null)        "
            + "    and (t4.out_plan_code like concat('%',#{p1.out_plan_code,jdbcType=VARCHAR},'%') or #{p1.out_plan_code,jdbcType=VARCHAR} is null)                             "
            + "    and (t4.in_plan_code like concat('%',#{p1.in_plan_code,jdbcType=VARCHAR},'%') or #{p1.in_plan_code,jdbcType=VARCHAR} is null)                                "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.start_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.start_time,jdbcType=DATE} is null)                "
            + "    and (DATE_FORMAT(t.out_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.over_time,jdbcType=DATE}, '%Y%m%d' ) or #{p1.over_time,jdbcType=DATE} is null)                  "
            + "    and (t.settlement_status = #{p1.settlement_status,jdbcType=VARCHAR} or #{p1.settlement_status,jdbcType=VARCHAR} is null or #{p1.settlement_status,jdbcType=VARCHAR} ='')                                 "
            + "    and (t.audit_status = #{p1.audit_status,jdbcType=VARCHAR} or #{p1.audit_status,jdbcType=VARCHAR} is null or #{p1.audit_status,jdbcType=VARCHAR} ='')         "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_start,jdbcType=DATE} is null)         "
            + "    and (DATE_FORMAT(t.in_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_time_end,jdbcType=DATE} is null)             "
            + "    and (t.status != #{p1.un_status} or #{p1.un_status} is null or #{p1.un_status} = '')"
            + "    and (t28.waybill_contract_no like concat('%', #{p1.waybill_contract_no}, '%') or #{p1.waybill_contract_no} is null or #{p1.waybill_contract_no} = '') "
            + "            <if test='p1.in_warehouse_types != null and p1.in_warehouse_types.length!=0' >                                                                       "
            + "             and t5.warehouse_type in                                                                                                                            "
            + "                 <foreach collection='p1.in_warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                         "
            + "                  #{item}                                                                                                                                        "
            + "                 </foreach>                                                                                                                                      "
            + "            </if>                                                                                                                                                "
            + "            <if test='p1.out_warehouse_types != null and p1.out_warehouse_types.length!=0' >                                                                     "
            + "             and t6.warehouse_type in                                                                                                                            "
            + "                 <foreach collection='p1.out_warehouse_types' item='item' index='index' open='(' separator=',' close=')'>                                        "
            + "                  #{item}                                                                                                                                        "
            + "                 </foreach>                                                                                                                                      "
            + "            </if>                                                                                                                                                "
//            + "    and (t.settlement_status = #{p1.settlement_status} or #{p1.settlement_status} is null or #{p1.settlement_status} = '')                                       "
            + "    and (DATE_FORMAT(t.out_audit_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.out_audit_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.out_audit_start,jdbcType=DATE} is null)"
            + "    and (DATE_FORMAT(t.out_audit_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.out_audit_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.out_audit_end,jdbcType=DATE} is null)  "
            + "    and (DATE_FORMAT(t.in_audit_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.in_audit_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_audit_start,jdbcType=DATE} is null) "
            + "    and (DATE_FORMAT(t.in_audit_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.in_audit_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.in_audit_end,jdbcType=DATE} is null)     "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &gt;= DATE_FORMAT(#{p1.c_time_start,jdbcType=DATE}, '%Y%m%d' ) or #{p1.c_time_start,jdbcType=DATE} is null)            "
            + "    and (DATE_FORMAT(t.c_time, '%Y%m%d' ) &lt;= DATE_FORMAT(#{p1.c_time_end,jdbcType=DATE}, '%Y%m%d' ) or #{p1.c_time_end,jdbcType=DATE} is null)                "
            + "    and (t27.name like concat('%', #{p1.out_audit_name}, '%') or #{p1.out_audit_name} is null or #{p1.out_audit_name} = '')                                      "
            + "    and (t26.name like concat('%', #{p1.in_audit_name}, '%') or #{p1.in_audit_name} is null or #{p1.in_audit_name} = '')                                         "
            + "    and (t30.code like concat('%', #{p1.container_code}, '%') or #{p1.container_code} is null or #{p1.container_code} = '')                                      "
            + "    and (DATE_FORMAT(t.c_time, '%Y-%m-%d' ) &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                                                        "
            + "    and (t.is_sync = #{p1.is_sync,jdbcType=VARCHAR} or #{p1.is_sync,jdbcType=VARCHAR} is null or #{p1.is_sync,jdbcType=VARCHAR} ='')                             "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.b_schedule_time_start,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_start,jdbcType=DATE} is null)                       "
            + "    and (DATE_FORMAT(t34.c_time, '%Y-%m-%d' ) &lt;= DATE_FORMAT(#{p1.b_schedule_time_end,jdbcType=DATE}, '%Y-%m-%d' ) or #{p1.b_schedule_time_end,jdbcType=DATE} is null)                "
            + "            <if test='p1.if_return_qty != null and p1.if_return_qty == 2' >                                                                                       "
            + "             and t35.qty is null                                                                                                                            "
            + "            </if>                                                                                                                                                "
            + "            <if test='p1.if_return_qty != null  and p1.if_return_qty == 1' >                                                                                      "
            + "             and t35.qty is not null                                                                                                                            "
            + "            </if>                                                                                                                                                "
            + "             and t4.type in ('"+DictConstant.DICT_B_SCHEDULE_TYPE_4+"','"+DictConstant.DICT_B_SCHEDULE_TYPE_5+"')                                                 "
            + "     ${p1.params.dataScopeAnnotation}                                                                                                                            "
            + "   </script>   ")
    List<BMonitorDirectExportVo> exportDirectDataAll(@Param("p1") BMonitorVo searchCondition);
}
